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
Files
Dockerfile
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 https://github.com/sstephenson/rbenv.git /root/.rbenv
RUN git clone https://github.com/sstephenson/ruby-build.git /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
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
db:
image: mysql:latest
environment:
MYSQL_DATABASE: app_development
MYSQL_USER: mysql
DATABASE_PASSWORD: onetwo
ROOT_PASSWORD: onetwo
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
ports:
- "4000:3000"
links:
- db
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)
I had the same problem for
mssql.link
, 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 :)
Issue:
I have gotten this error whenever
docker-compose
successfully builds a set ofImages
, but one of thoseImages
fails to run (e.g. launch into its ownContainer
).In this case, I suspect the
Image
, underlying yourpuma_db_1
Container
, is failing torun
. You can find the name of thisImage
by runningdocker ps -a
. That said, its name is most likelypuma_db
Solution:
To get at the cause, you can try
docker-compose up <service_name>
ordocker-compose up db
Alternatively, I find the error message by running
docker run <image_name>
more useful. In this case, that would bedocker run puma_db
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
.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.ymlI had the same problem with elasticsearch - symfony - and docker
the solution is to delete the content of the data volume
elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:5.5.2 Volumes: - ./docker/volume/elasticsearch: /usr/share/elasticsearch/data
and rundocker-composer up -d
again.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:If it appears the MySQL service is not running after this command, then you found the origin of your problem.