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

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

无法启动容器9b271c58cf6aecaf017dadaf5b无法链接到未运行的容器:/ 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 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"]

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服务未运行,则表明问题的根源。

以上是 Docker无法链接到未运行的容器 的全部内容, 来源链接: utcz.com/qa/408158.html

回到顶部