Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build container with docker-compose, but run /etc/bash with -it option later?

I'm using docker-compose for development. During the process, I often need to build 5 containers (1 for web-server and 4 for postgres, redis, mongo, etc.). The web server container is configured to include links for other containers, it has it's own ENV vars, mounted volumes from development host machine.

The problem is I don't need web container to run server itself. Istead of this I need to exec /etc/bash with -it options inside web container after all dependent containers are created. Thats why, my dockerfile for web-container ends with:

CMD /bin/true

Obviously, such container wont be running, so I can't use smth like

docker exec -it <CONTAINER ID> /bin/bash

to "enter" it and run node app.js or some other tasks.

Any way to build container with compose as a part of docker-compose.yml file, but run /etc/bash with -it option later?

BTW, certainly I can manually start a separate web-container with

docker run \
--link postgres
--link ...
-e "NODE_ENV=development" \
-e ... \
...
...
..

but it this case I need to append all links, env vars, volumes, etc. as argumets everytime I'm going to develop an app.

like image 346
f1nn Avatar asked Sep 05 '15 17:09

f1nn


1 Answers

Looks like docker-compose run will become your friend. From the docker compose docs:

Runs a one-time command against a service. For example, the following command starts the web service and runs bash as its command.

$ docker-compose run web bash

The command docker-compose run <service-name> also ensures that all required containers (e.g. those providing volumes and links) will be started prior to the container <service-name>, if they are not already running.

In case you use any port-mappings, you might consider using docker-compose run --service-ports <service-name>. Without that option docker-compose will only map ports when using docker-compose up.

Like with docker run you can also use the --rm option to remove containers once you are done with them.

If your image uses ENTRYPOINT, you should consider overriding this in your docker-compose.yml with entrypoint: /bin/bash.

like image 151
Jan Suchotzki Avatar answered Nov 09 '22 02:11

Jan Suchotzki