Running app through docker-compose doesn't work with default network
See original GitHub issueWorking on Ubuntu 18.04, when I run the app through docker-compose I get nothing in the browser.
Running the two containers from the command line works fine, with the commands below:
~/dev/docker/app$ docker run -d \
--network todo-app \
--network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
~/dev/docker/app$ docker run -dp 3000:3000 \
-w /app -v ${PWD}:/app \
--network todo-app \
-e MYSQL_HOST=mysql \
-e MYSQL_USER=root \
-e MYSQL_PASSWORD=secret \
-e MYSQL_DB=todos \
node:12-alpine \
sh -c "yarn install && yarn run dev"
But when I run it using docker-compose, it fails, without any errors (other than the working version). The docker-compose.yml is according to the tutorial:
version: "3.7"
services:
app:
image: node:12-alpine
command: sh -c "yarn install && yarn run dev"
ports:
- 3000:3000
working_dir: /app
volumes:
- ./:/app
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: secret
MYSQL_DB: todos
mysql:
image: mysql:5.7
volumes:
- todo-mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: todos
volumes:
todo-mysql-data:
The logging output of the mysql container is the same, same warnings. Why don’t I see anything in the browser?
mysql database
I can log into the database, using docker exec -it e46fae64e430 mysql -p todos
. But they don’t point to the same todos
database. The ‘composer’ version is empty, the other contains the test data I entered before.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Cannot link to a running container started by docker-compose
In my case, the network is named as myapp_default. Note: Your app's network is given a name based on the “project name”, which...
Read more >Networking in Compose - Docker Documentation
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both...
Read more >Try Docker Compose - Docker Documentation
From your project directory, type docker compose up to build the app with the updated Compose file, and run it. $ docker compose...
Read more >Use Docker Compose - Docker Documentation
To remember, this was the command we were using to define our app container. $ docker run -dp 3000:3000 \ -w /app -v...
Read more >Frequently asked questions - Docker Documentation
Docker Compose FAQ. ... It then waits for a default timeout of 10 seconds. ... causes Docker to run your process using bash...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was having trouble getting docker-compose tutorial working. mysql container was not able to initialize the database. I found that volume “todo-mysql-data” from previous tutorial was still there and probably that was conflicting. So i removed that volume and tried again and it worked.
I have it running now, adding the following to the docker-compose.yml to force the apps to use the previously created network ‘todo-app’:
This works now, but clearly, the default network should have worked as well. Anybody a suggestion what is causing this behaviour? A bug in docker(compose)? Something I did wrong somewhere?
Also what confuses me is that the mysql database in both situaties use the same volumes and give the same output on
SHOW VARIABLES WHERE Variable_Name LIKE "%dir" ;
, but show other data.