An image
is a set of layers. When you start an image
, it becomes a running container
. You can have many running container
s of the same image.
An instance of an image
is called a container
.
The image
is the recipe, the container
is the cake. You can make as many cakes as you like with a given recipe. A stopped container
is a cake in the freezer.
A volume
is a virtual drive which enables us to persist data and share between containers.
docker-compose up
docker-compose up -d
The -d
flag backgrounds the process and log output.
To view logs for a specific container, use docker-compose logs [container]
The docker-compose stop
command will stop your containers, but it won’t remove them.
The docker-compose down
command will stop your containers, but it also removes the stopped containers as well as any networks that were created.
You can take down
1 step further and add the -v flag to remove all volumes too. This is great for doing a full blown reset on your environment by running docker-compose down -v
.
docker logs -ft container_name
https://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container
mycontainer
is a container ID, not an image ID. Get the image ID with docker ps
The cp command can be used to copy files. One specific file can be copied into the container like:
docker cp foo.txt mycontainer:/foo.txt
docker cp mycontainer:/foo.txt foo.txt
Multiple files contained by the folder src
can be copied into the target
folder using:
docker cp src/. mycontainer:/target
docker cp mycontainer:/src/. target
You can also copy files out of a container:
docker cp divihub-test_phpfpm_1:/usr/local/etc/php-fpm.d/www.conf .
docker cp <containerId>:/file/path/within/container /host/path/target
docker ps
docker ps -a
See: https://docs.docker.com/compose/reference/exec/
In this example wp
is the service defined in the docker-compose.yml
docker-compose exec <service> bash
docker-compose exec <docker_name> bash
docker-compose exec wp bash
# or
docker exec -ti <docker_name> /bin/bash
docker exec -ti divi-card-factory-rsmm_wp_1 /bin/bash
docker kill $(docker ps -q)
-s
flag also shuts down running containers if needed
docker-compose rm -s
docker rm <container_ID>
The ones that are not tagged properly and are hanging around usually as the result of the intermediate container creation:
docker rmi $(docker images -q -f dangling=true)
docker images -a
docker rmi Image Image
Recreating the images is as simple as restarting the application. Leaves the volumes
docker-compose up --build
docker inspect --format="{{.Mounts}}" <container_id>
docker volume ls
docker volume rm <name_of_volume>
docker volume prune
docker system prune
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:
docker system prune -a