[SOLVED] The Container Name Is Already In Use By Container

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 to be able to reuse that name.

This short note shows how to fix “the container name is already in use by container” error. (more…)

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 this image even though it is available in the registry.

Below i will show how to force the docker-compose up command to pull the latest version of the images. (more…)

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 ... command.

Alternatively, you can pass multiple environment variables from an external file with the env_file option, just like with a docker run --env-file=FILE ... command.

In this short note i will show the examples of how to set the environment variables in the Docker Compose using the environment and env_file options. (more…)

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 a Docker Compose file. (more…)

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.

Below i will show an example of how to specify the alternate path to the Dockerfile in the build section of the Docker Compose file. (more…)

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 also show how to build an Alpine-based Docker image with additionally installed packages. (more…)

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 receive the “unauthorized: authentication required” error.

This guide explains how to log in and how to log out of a private Docker Registry from the command line using the docker login and docker logout commands. (more…)