Is it possible to start myapp-1 with myapp-2, then sleep for 30 seconds and only then start myapp-3?
Tried this docker-compose.yml with no luck.
version: '3'
services:
myapp-1:
container_name: myapp-1
image: myapp:latest
restart: always
myapp-2:
container_name: myapp-2
image: myapp:latest
restart: always
test-sleep:
image: busybox
command: ["/bin/sleep", "30"]
depends_on:
- "myapp-1"
- "myapp-2"
myapp-3:
container_name: myapp-3
image: myapp:latest
restart: always
depends_on:
- "test-sleep"
The docker-compose.yml you proposed could not address your use case, as the depends_on property does not wait for the dependencies to be ready (or terminated), but only for them to be started (i.e., in your example, myapp-3 is started as soon as the /bin/sleep 30 command has been started).
See e.g. the corresponding doc:
depends_on does not wait for [dependencies] to be “ready” before starting [the service] - only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.
The link above mentions several tools (including wait-for-it) that could be used to wait that some service dependencies are ready (provided they expose a web service at a given TCP port).
Otherwise, if you just want to wait for 30s before starting myapp-3, assuming the Dockerfile of myapp-3 contains CMD ["/prog", "first argument"], you could just get rid of test-sleep and write something like:
version: '3'
services:
myapp-1:
container_name: myapp-1
image: myapp:latest
restart: always
myapp-2:
container_name: myapp-2
image: myapp:latest
restart: always
myapp-3:
container_name: myapp-3
image: myapp:latest
restart: always
command:
- '/bin/sh'
- '-c'
- '/bin/sleep 30 && /prog "first argument"'
depends_on:
- "myapp-1"
- "myapp-2"
Related
I have an app with separated frontend and backend, each one is a subfolder. I have dockerized the front and the back separately in their folders, respectively.
Now, I'm trying to run them in the same network by using docker-compose in the root folder. The build is done successfully, but when I run it, the front container works just fine, but the back container exits with code 0.
Maybe it's worth mentioning that the container of the back is a done with a docker-compose too.
Can you help me please?
Here's how the docker-compose.yml looks like in the root folder
version: '3.7'
services:
back:
build: ./backend/
ports:
- "8000:8000"
front:
build: ./frontend/
ports:
- "80:3000"
output:
app_back_1 exited with code 0
front_1 | INFO: Accepting connections at http://localhost:3000.
Here's the docker-compose file of the backend:
version: '3.5'
services:
app:
build:
context: .
command: gunicorn backend.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_data:/vol/static
ports:
- "8000:8000"
restart: always
env_file:
- .env
depends_on:
- app-db
app-db:
image: postgres:12-alpine
ports:
- "5432:5432"
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data:rw
env_file:
- .env
proxy:
build: ./proxy
volumes:
- static_data:/vol/static
- media_data:/vol/media
restart: always
ports:
- "8008:80"
depends_on:
- app
volumes:
static_data:
media_data:
postgres_data:
If the container runs well, It should run well with identical docker image that you have built. Try docker-compose up --build --force-recreate --no-deps to recreate everything from scratch with no cache, so then if you have error in your source code the error will throw for both standalone container and compose.
I'm trying to play around with configuring agents and such through Docker. I have this compose file:
services:
puppetserver:
container_name: puppetserver
hostname: puppet
image: puppet/puppetserver
links:
- puppetdb
networks:
- puppetnet
depends_on:
- puppetdb
puppetdb:
container_name: puppetdb
hostname: puppetdb
image: puppet/puppetdb
networks:
- puppetnet
restart: always
agent:
container_name: agent
hostname: agent
image: puppet/puppet-agent
links:
- puppetserver
networks:
- puppetnet
restart: always
networks:
puppetnet:
name: puppetnet
After I spin it up, the agent restarts a few times waiting for the puppet server to come up but then goes into restart and stays there forever.
I read the puppet/puppet-agent page closer and it says
Note that this is of limited use outside testing, in that this code changes the running container, which then exits.
So the infinite restarts is to be expected.
I'm trying do deploy a simple node - redis architecture using docker-compose.
I have a dump.rdb with the backup of redis data and I want to launch a container with that data loaded.
My docker-compose.yml looks like this:
version: '3'
services:
redis:
image: redis:alpine
container_name: "redis"
ports:
- "6379:6379"
server:
build: ./src
image: hubName:imageName
container_name: containerName
links:
- redis
depends_on:
- "redis"
ports:
- "8443:8443"
restart: always
Should I include volumes? What if I want persistance of that redis data?
Thanks :)
You can use docker-compose.yml like :
version: '3'
services:
redis:
image: redis:alpine
container_name: "redis"
ports:
- "6379:6379"
volumes:
- /data/redis:/data
server:
build: ./src
image: hubName:imageName
container_name: containerName
links:
- redis
depends_on:
- "redis"
ports:
- "8443:8443"
restart: always
Let's copy your dump.rdb to /data/redis folder on your host machine then start docker-compose.
About redis persistance,you must have docker volume and have two types for redis persinstance: RDB and AOF
RDB: The RDB persistence performs point-in-time snapshots of your dataset at specified intervals ( example: 60 seconds or if there're at least 10000 keys have been changed)
AOF: logs every write operation received by the server(eg: SET command) , that will be played again at server startup, reconstructing the original dataset
For more: https://redis.io/topics/persistence
You should decide base on your critical data level. In this case you have rdb dump so you can use RDB, it's default option
There's option to pass command line parameters to the docker-compose so I can have more flexibility with docker compose file. But I have issue and it's not really clear why it happens. So here's the relevant docker compose
filesdocker-compose.yml
version: '2'
services:
mongo:
image: mongo:3.2
restart: always
volumes:
- /mnt/data/mongodb/data/db:/data/db
redis:
image: redis:3
restart: always
application:
build: .
ports:
- "3000:3000"
links:
- mongo:mongo
- redis:redis
restart: always
And another file docker-deploy.yml
version: '2'
services:
application:
image: myregistry.com:5000/myapplication:${APP_VERSION}
links:
- mongo:mongo
- redis:redis
restart: always
Now if I run command line APP_VERSION=stage/1.1 docker-compose -f docker-compose.yml -f docker-deploy.yml pull application to pull the application image with a particular version it fails with output
Pulling application (myregistry:5000/myapplication:stage/1.1:latest)...
ERROR: invalid reference format
Note the latest added at the end. What's going on ? Where did it come from ?
You want this to be:
`version: '2'
services:
application:
image: myregistry.com:5000/myapplication/${APP_VERSION}
links:
- mongo:mongo
- redis:redis
restart: always`
Note that I replaced the : with /
And also set your APP_VERSION=stage:1.1
I'm learning how to use docker-compose following the official documentation: https://docs.docker.com/compose/gettingstarted/
When browsing to http://myserver.com:5000 I have the expected result:
Hello World! I have been seen 1 times.
I would like to change the listening port to 5001 modifying the docker-compose.yml file as follow:
version: '2'
services:
web:
build: .
ports:
- "5001:5001"
volumes:
- .:/code
depends_on:
- redis
redis:
image: redis
Unfortunately, after stop and removing the container (with 'docker-compose down') and start it again (with 'docker-compose up -d'), the connection to http://myserver.com:5001 is refused.
Any idea?
You should change the external port only (the first port number in xxxx:xxxx)
version: '2'
services:
web:
build: .
ports:
- "5001:5000"
volumes:
- .:/code
depends_on:
- redis
redis:
image: redis
Link to documentation:
https://docs.docker.com/compose/compose-file/compose-file-v3/#ports