While starting a Docker container, you may sometimes receive “the container name is already in use by container” error. The complete error looks like as follows: ERROR: for <containerName> Cannot create container for service <serviceName>: Conflict. The container name “<containerName>” is already in use by container “<containerID>”. You have to remove (or rename) that container […]
docker
Docker Compose: Pull Latest Image Version
The docker-compose up command doesn’t check a registry for a newer version of an image if it finds the image:latest among the locally cached images. So after a while you may find, that despite of the :latest tag of the image in a docker-compose.yml file, the docker-compose up command doesn’t pull the latest version of […]
Docker Compose: Set Environment Variables
In a Docker Compose, you can set environment variables in a service’s containers or overwrite variables that are defined in the Dockerfile of the images you’re running. To pass the environment variables to the containers, you can use the environment key in a docker-compose.yml file, that works just like a docker run -e VAR=VALUE … […]
Docker Compose: (re)Start|Stop|Build – Single Service
By default, the docker-compose (up|stop|restart|build) commands will start, stop, restart or build all of the services (containers) listed in a docker-compose.yml file. But there is also a way to run docker-compose commands against the certain containers only. This is useful when you need for example to re-build just one container described as a service in […]
Docker Compose: Detached Mode (Background)
By default, a Docker Compose starts the services in the foreground mode just like a docker run command. To run the Docker Compose in the background, a docker-compose up command should be started with the -d or –detach option. In this short note i am showing how to run the Docker Compose in the detached […]
Docker Compose: Specify Dockerfile Path – Example
The docker-compose build or docker-compose up –build commands read the docker-compose.yml file looking for all services containing the build configuration option and run a docker build command for each of them. If the Dockerfile has been renamed or placed out of the context directory, you can specify the alternate path in the Docker Compose file. […]
Docker: Remove All Images & Containers
This short note shows how to remove all Docker images and containers. Use these commands with caution as they force the removal of all the Docker images and containers including the running ones.
Alpine: Install Package
A minimal Docker image based on Alpine Linux has only 5 MB in size, but a lot of packages common for Linux distributions are not installed by default. In this short note i will show how to install a package in Alpine container from the command line using the apk (Alpine package manager). I will […]
Docker: Login Command – Registry Login & Logout
To start using a private Docker Registry a user usually should run the docker login command and set a username and password that will be cached locally. If a user tries to docker pull or docker push an image from/to a private Docker Registry, without having run the docker login command in advance, he may […]
Docker: Run Multiple Commands in Container
Multiple commands can be executed in a running Docker container using the docker exec command. If the Docker container is stopped, before running the docker exec command it should be started using the docker run command. In this short note i will show the examples of how to execute multiple commands in a Docker container.