1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DockerコンテナのStateがExit7になった時の対処法

Last updated at Posted at 2021-09-09

##困ったこと
ローカルホスト(今回はlocalhost:3000)に接続しようとdocker-compose up -dしてもうまくいかない。
昨日gem追加したからそのせいかな、と思いつつも色々試行錯誤してなんとか解決しました。
##今の状態を確認
docker-compose up -dをしたときは良さげな感じ。でもブラウザ見ると接続できてない。

$ docker-compose up -d
Starting qiita_db_1 ... done
Starting qiita_web_1 ... done

docker-compose psでコンテナ一覧を表示してみるとStateがExit 7となっている。

$ docker-compose ps
    Name                  Command               State           Ports       
----------------------------------------------------------------------------
qiita_db_1    docker-entrypoint.sh mysqld      Up       3306/tcp, 33060/tcp
qiita_web_1   bundle exec rails s -p 300 ...   Exit 7   

docker logs qiita_web_1で原因を探ってみる

$ docker logs qiita_web_1
Could not find bcrypt-3.1.16 in any of the sources
Run `bundle install` to install missing gems.

ログ通りにbundle installしようとしたが、なんかうまくいかなかった。
##解決方法
docker-compose buildしてからdocker-compose up -dする。

$ docker-compose build
db uses an image, skipping
Building web
[+] Building 36.0s (13/13) FINISHED                                                                                                                                                                         
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 37B                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/ruby:2.7.0                                                                                                                                          0.0s
 => [internal] load build context                                                                                                                                                                      0.7s
 => => transferring context: 10.46MB                                                                                                                                                                   0.7s
 => [1/8] FROM docker.io/library/ruby:2.7.0                                                                                                                                                            0.0s
 => CACHED [2/8] RUN apt-get update -qq && apt-get install -y build-essential nodejs                                                                                                                   0.0s
 => CACHED [3/8] RUN mkdir /app                                                                                                                                                                        0.0s
 => CACHED [4/8] WORKDIR /app                                                                                                                                                                          0.0s
 => [5/8] COPY Gemfile /app/Gemfile                                                                                                                                                                    0.1s
 => [6/8] COPY Gemfile.lock /app/Gemfile.lock                                                                                                                                                          0.0s
 => [7/8] RUN bundle install                                                                                                                                                                          33.7s
 => [8/8] COPY . /app                                                                                                                                                                                  0.3s
 => exporting to image                                                                                                                                                                                 1.2s 
 => => exporting layers                                                                                                                                                                                1.2s 
 => => writing image sha256:963e2a37244ddae131525b434210cff12357decab259e971c5ec4edb27409498                                                                                                           0.0s 
 => => naming to docker.io/library/qiita_web                                                                                                                                                          0.0s 
                                                                                                                                                                                                            
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

$ docker-compose up -d
qiita_db_1 is up-to-date
Recreating qiita_web_1 ... done

docker-compose psで再度コンテナを表示すると、StateがUpになった。

$ docker-compose ps
    Name                  Command               State                    Ports                  
------------------------------------------------------------------------------------------------
qiita_db_1    docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp                     
qiita_web_1   bundle exec rails s -p 300 ...   Up      0.0.0.0:3000->3000/tcp,:::3000->3000/tcp

ブラウザで試してみると接続できるようになってるはず

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?