I tried to attach the Rails container with Docker but they said "You cannot attach to a stopped container, start it first"
But I executed $docker ps once, they are working, but if I tried to execute $docker attach [rails container name], it's gone.
I tried $docker restart [rails container name], but it's not working like below.
Anyone knows how should I resolve this problem??
I use MacOS10.13.6、and docker version is 19.03.8, and ruby version on Docker is 2.4.5.
$ docker-compose build
db uses an image, skipping
Building web
Step 1/8 : FROM ruby:2.4.5
---> a14928bdfa34
Step 2/8 : RUN apt-get update -qq && apt-get install -y build-essential nodejs
---> Using cache
---> 440899707638
Step 3/8 : RUN mkdir /app
---> Using cache
---> b298382e3fca
Step 4/8 : WORKDIR /app
---> Using cache
---> 1bd9c799818c
Step 5/8 : COPY Gemfile /app/Gemfile
---> Using cache
---> 4a7ad7441bfe
Step 6/8 : COPY Gemfile.lock /app/Gemfile.lock
---> Using cache
---> 916a18caba9f
Step 7/8 : RUN bundle install
---> Using cache
---> c03081abfed0
Step 8/8 : COPY . /app
---> Using cache
---> e2a7496170af
Successfully built e2a7496170af
Successfully tagged fullstack_web:latest
$ docker-compose up -d
fullstack_db_1 is up-to-date
Starting fullstack_web_1 ... done
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e117a2a95ad3 fullstack_web "bundle exec rails s…" 16 minutes ago Up 3 seconds 0.0.0.0:3000->3000/tcp fullstack_web_1
954bc6c3627f mysql:5.7 "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 3306/tcp, 33060/tcp fullstack_db_1
$ docker attach fullstack_web_1
You cannot attach to a stopped container, start it first
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
954bc6c3627f mysql:5.7 "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 3306/tcp, 33060/tcp fullstack_db_1
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e117a2a95ad3 fullstack_web "bundle exec rails s…" 16 minutes ago Exited (1) 18 seconds ago fullstack_web_1
954bc6c3627f mysql:5.7 "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 3306/tcp, 33060/tcp fullstack_db_1
$ docker restart fullstack_web_1
fullstack_web_1
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e117a2a95ad3 fullstack_web "bundle exec rails s…" 16 minutes ago Up 1 second 0.0.0.0:3000->3000/tcp fullstack_web_1
954bc6c3627f mysql:5.7 "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 3306/tcp, 33060/tcp fullstack_db_1
$ docker attach fullstack_web_1
You cannot attach to a stopped container, start it first
More Information
I tried to use "pry-byebug" on Docker container. So I added "gem pry-byebug" in my Gemfile. Then after that, I tried to attach rails container like above.
And this is Github↓ bit.ly/2U5ulA6