MySQL Docker 无法链接到未运行的容器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32147554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Docker Cannot link to a non running container
提问by kalelc
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
我需要使用 docker-compose 创建 Rails 和 Mysql 容器。当我尝试在容器之间创建链接时docker-compose up
,我得到
Cannot start container 9b271c58cf6aecaf017dadaf5b Cannot link to a non running container: /puma_db_1 AS /puma_web_1/db
无法启动容器 9b271c58cf6aecaf017dadaf5b 无法链接到非运行容器:/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
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
回答by Thomasleveil
Most likely the db
container fails to start.
很可能db
容器无法启动。
Make sure it works fine by starting only the db
service. You can do that with the following command:
通过仅启动db
服务来确保它正常工作。您可以使用以下命令执行此操作:
docker-compose up db
If it appears the MySQL service is not running after this command, then you found the origin of your problem.
如果在此命令后出现 MySQL 服务未运行,那么您就找到了问题的根源。
回答by Mike Graf
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
与 MySQL 没有特别的关系,但更多的是消息 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)
我发现依赖容器的 ID 与给定的 ID 不同(b2f21b869ccc
在我上面的示例中)
Solved simply by running
docker-compose up -d --force-recreate <service>
只需运行即可解决
docker-compose up -d --force-recreate <service>
which caused it to recreate the dependency and fix the link to the correct docker id
这导致它重新创建依赖项并将链接修复到正确的 docker id
回答by Ville Laitila
For me, it did not help running docker-compose up db.
对我来说,它没有帮助运行 docker-compose up db。
This did the trick for me:
这对我有用:
sudo service docker restart
sudo service docker restart
and then continuing with docker-compose up (-d)
然后继续 docker-compose up (-d)
回答by JorelC
You might try out the new features of docker networking, To do this, You must remove the linkparameter in your docker-compose.yml, and initialize the container with the --x-networking option
.
您可以尝试 docker 网络的新功能,为此,您必须删除docker-compose.yml中的link参数,并使用.--x-networking option
docker-compose --x-networking up -d
To prevent docker generate random names for the containers, which are added to the /etc/hostsfile of the respective network for every container, you can use the container_name:
key in the docker-compose.yml
为了防止 docker 为容器生成随机名称,这些名称被添加到每个容器各自网络的/etc/hosts文件中,您可以使用docker-compose.yml 中的container_name:
密钥
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"
回答by bgerd
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
每当
docker-compose
成功构建一组 时Images
,我都会收到此错误,但其中一个Images
无法运行(例如启动到它自己的Container
)。在这种情况下,我怀疑
Image
您的基础puma_db_1
Container
未能run
。您可以Image
通过运行找到它的名称docker ps -a
。也就是说,它的名字很可能是puma_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
要找出原因,您可以尝试
docker-compose up <service_name>
或docker-compose up db
或者,我通过运行发现错误消息
docker run <image_name>
更有用。在这种情况下,那就是docker run puma_db
回答by bgerd
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:
我遇到了同样的问题mssql.link
,因为我没有使用本地数据库(而是使用我们在登台时使用的数据库),我所要做的就是通过编辑 Dockerfile 脚本来注释该行:
# 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 :)
这个解决方案可能对某人有帮助,也可能对某人没有帮助,但它为我整理了它:)
回答by sapy
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.
如果您lets say X
使用链接启动容器,--link keen_visvesvaraya
然后一旦X
启动,链接的容器就会停止,但会X
继续运行。现在,如果您尝试docker exec
进入,X
则会收到此错误。
Yah solution is to restart.
解决方法是重启呀。
回答by Moccine
I had the same problem with elasticsearch - symfony - and docker
我对 elasticsearch - symfony - 和 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.
? elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.5.2
Volumes:
???? - ./docker/volume/elasticsearch: /usr/share/elasticsearch/data
并docker-composer up -d
再次运行。
回答by Pramod Kumar Gupta
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