Docker Community Forums

Share and learn in the Docker community.

Linking containers


(Mahantas) #1

I was reading a tutorial on linking docker containers.First they have created a container which runs redis image:

docker run -d --name redis-server redis

then:

docker run -it --link redis-server:redis redis redis-cli -h redis

I do not understand some part of the command. redis-cli -h redis I understand, but why it is being prepended by redis?


(Paulxroot) #2

docker run has to be called like that:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

That means in

docker run -d --name redis-server redis

redis-server is the name of the container that is created by the command and redis is the image from which the container is built.

docker run -it --link redis-server:redis redis redis-cli -h redis

means a container from the image ‘redis’ will be created, and the command ‘redis-cli -h redis’ will be executed on it. The tutorial probably wants to tell you that ‘-h “name of other container”’ works because of the linking.
The names have been chosen a bit confusing by the creaters of that tutorial.