Docker Cannot link to a non running container

I need to create Rails and Mysql containers with docker-compose. When I try to create links between containers with docker-compose up, I get

Cannot start container
9b271c58cf6aecaf017dadaf5b Cannot link to a non running container:
/puma_db_1 AS /puma_web_1/db



FROM ubuntu:14.04

RUN apt-get -y update
RUN apt-get -y install git curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

RUN apt-get -y install libmysqlclient-dev
RUN git clone /root/.rbenv
RUN git clone /root/.rbenv/plugins/ruby-build
RUN echo 'eval "$(rbenv init -)"' >> $HOME/.profile
RUN echo 'eval "$(rbenv init -)"' >> $HOME/.bashrc

RUN rbenv install 2.1.5
RUN rbenv global 2.1.5
RUN gem install rails -v 4.0.11

ADD app.tar.gz /home/
WORKDIR /home/app

RUN bundle install
CMD ["rails", "server", "-b", ""]


  image: mysql:latest
    MYSQL_DATABASE: app_development
    MYSQL_USER: mysql
    ROOT_PASSWORD: onetwo
  build: .
  command: bundle exec rails s -p 3000 -b ''
    - "4000:3000"
    - db


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Most likely the db container fails to start.

Make sure it works fine by starting only the db service. You can do that with the following command:

docker-compose up db

If it appears the MySQL service is not running after this command, then you found the origin of your problem.

Method 2

Not specifically related to MySQL but more the message ERROR: for <service> Cannot link to a non running container: /b2f21b869ccc_<dependency>_1 AS /<service>_1/<dependency>_1

I found that the dependency container had a different id than the one given (b2f21b869ccc in my example above)

Solved simply by running

docker-compose up -d --force-recreate <service>

which caused it to recreate the dependency and fix the link to the correct docker id

Method 3

For me, it did not help running docker-compose up db.

This did the trick for me:

sudo service docker restart

and then continuing with docker-compose up (-d)

Method 4

You might try out the new features of docker networking, To do this, You must remove the link parameter in your docker-compose.yml , and initialize the container with the --x-networking option.

docker-compose --x-networking up -d

To prevent docker generate random names for the containers, which are added to the /etc/hosts file of the respective network for every container, you can use the container_name: key in the docker-compose.yml

  container_name: db
  image: mysql:latest
    MYSQL_DATABASE: app_development
    MYSQL_USER: mysql
    ROOT_PASSWORD: onetwo
  container_name: web
  build: .
  command: bundle exec rails s -p 3000 -b ''
    - "4000:3000"

Method 5


  • I have gotten this error whenever docker-compose successfully
    builds a set of Images, but one of those Imagesfails to
    run (e.g. launch into its own Container).
  • In this case, I suspect the Image, underlying your
    puma_db_1 Container, is failing to run. You can
    find the name of this Image by running docker ps -a. That said, its name is most likely puma_db


  • To get at the cause, you can try docker-compose up
    or docker-compose up db
  • Alternatively, I find the error message by running docker run
    more useful. In this case, that would be docker
    run puma_db

Method 6

I had the same problem for, as I am not using local database (rather using the one we have on staging), all I had to do is just comment that line out by editing Dockerfile script:


This solution may help someone or may be no one, but it sorted it for me 🙂

Method 7

If you started the container lets say X with a link --link keen_visvesvaraya and then once X is up the linked container was stopped, but X kept running . Now if you try to docker exec into X you get this error.

Yah solution is to restart.

Method 8

I had the same problem with elasticsearch – symfony – and docker

Can not link to a non-running container:/43c1d3b410db_myindex_elasticsearch_1 AS /myindex_apache_1/elasticsearch

the solution is to delete the content of the data volume

     - ./docker/volume/elasticsearch: /usr/share/elasticsearch/data

and run docker-composer up -d again.

Method 9

You can use below command Because It’s working for me

docker run --name standlone-mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test -e MYSQL_USER=root -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6

Method 10

you need to modify the db: in yml file to include “POSTGRES_HOST_AUTH_METHOD” in environment section


All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x