Docker 无法链接到未运行的容器

Docker Cannot link to a non running container(Docker 无法链接到未运行的容器)
本文介绍了Docker 无法链接到未运行的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 docker-compose 创建 Rails 和 Mysql 容器.当我尝试使用 docker-compose up 在容器之间创建链接时,我得到

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

无法启动容器9b271c58cf6aecaf017dadaf5b 无法链接到未运行的容器:/puma_db_1 AS/puma_web_1/db

Cannot start container 9b271c58cf6aecaf017dadaf5b Cannot link to a non running container: /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 容器无法启动.

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:

docker-compose up db

如果执行此命令后 MySQL 服务没有运行,那么您找到了问题的根源.

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

这篇关于Docker 无法链接到未运行的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)