Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I create a data-container only using docker-compose.yml?

This question is coming from an issue on the Docker's repository:
https://github.com/docker/compose/issues/942

I can't figure it out how to create a data container (no process running) with docker compose.

like image 697
ivan Avatar asked Oct 02 '15 13:10

ivan


People also ask

Does docker compose create containers?

Creates containers for a service.

Can I use docker compose instead of Dockerfile?

Docker Compose (herein referred to as compose) will use the Dockerfile if you add the build command to your project's docker-compose. yml . Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.


1 Answers

UPDATE: Things have changed in the last years. Please refer to the answer from @Frederik Wendt for a good and up-to-date solution.

My old answer: Exactly how to do it depends a little on what image you are using for your data-only-container. If your image has an entrypoint, you need to overwrite this in your docker-compose.yml. For example this is a solution for the official MySql image from docker hub:

DatabaseData:   image: mysql:5.6.25   entrypoint: /bin/bash  DatabaseServer:   image: mysql:5.6.25   volumes_from:     - DatabaseData   environment:     MYSQL_ROOT_PASSWORD: blabla 

When you do a docker-compose up on this, you will get a container like ..._DatabaseData_1 which shows a status of Exited when you call docker ps -a. Further investigation with docker inspect will show, that it has a timestamp of 0. That means the container was never run. Like it is stated by the owner of docker compose here.

Now, as long as you don't do a docker-compose rm -v, your data only container (..._DatabaseData_1) will not loose its data. So you can do docker-compose stop and docker-compose up as often as you like.

In case you like to use a dedicated data-only image like tianon/true this works the same. Here you don't need to overwrite the entrypoint, because it doesn't exist. It seems like there are some problems with that image and docker compose. I haven't tried it, but this article could be worth reading in case you experience any problems.

In general it seems to be a good idea to use the same image for your data-only container that you are using for the container accessing it. See Data-only container madness for more details.

like image 123
Jan Suchotzki Avatar answered Oct 10 '22 17:10

Jan Suchotzki