Programing

Docker는 실행되지 않는 컨테이너에 연결할 수 없습니다.

lottogame 2021. 1. 6. 07:38
반응형

Docker는 실행되지 않는 컨테이너에 연결할 수 없습니다.


docker-compose로 Rails 및 Mysql 컨테이너를 만들어야합니다. 를 사용하여 컨테이너간에 링크를 만들려고 docker-compose up하면

컨테이너를 시작할 수 없습니다. 9b271c58cf6aecaf017dadaf5b 실행되지 않는 컨테이너에 연결할 수 없습니다. / puma_db_1 AS / puma_web_1 / db

파일

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

대부분 db컨테이너가 시작되지 않습니다.

db서비스 만 시작하여 제대로 작동하는지 확인하십시오 . 다음 명령으로 수행 할 수 있습니다.

docker-compose up db

이 명령 이후에 MySQL 서비스가 실행되지 않는 것으로 나타나면 문제의 원인을 찾은 것입니다.


MySQL과 특별히 관련이 없지만 더 많은 메시지 ERROR: for <service> Cannot link to a non running container: /b2f21b869ccc_<dependency>_1 AS /<service>_1/<dependency>_1

종속성 컨테이너의 ID가 주어진 것과 다른 것을 발견했습니다 ( b2f21b869ccc위의 예에서).

간단히 실행하여 해결 docker-compose up -d --force-recreate <service>

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


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)


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

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

Issue:

  • 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

Solution:

  • To get at the cause, you can try docker-compose up <service_name> or docker-compose up db

  • Alternatively, I find the error message by running docker run <image_name> more useful. In this case, that would be docker run puma_db


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:

# DOCKER_ARGS="${DOCKER_ARGS} --link mssql-server-linux:mssql.link"

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


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.


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

  elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:5.5.2 Volumes:      - ./docker/volume/elasticsearch: /usr/share/elasticsearch/data and run docker-composer up -d again.

ReferenceURL : https://stackoverflow.com/questions/32147554/docker-cannot-link-to-a-non-running-container

반응형