0
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 1 year has passed since last update.

Docker Tutorial #2 Docker run and stop (2023)

Last updated at Posted at 2023-05-21

image.png

Target commands

docker run
docker stop (container ID)
docker start (container ID)
docker logs (container ID)
docker rm -f (container ID)

Docker run

I will try running the NGINX image.

terminal
    docker run -d -p 8080:80 nginx

image.png

I will check the running containers.

terminal
    docker ps --format "CONTAINER ID:  {{.ID}}\nIMAGE:    {{.Image}}\nCOMMAND:  {{.Command}}\nCREATED:  {{.CreatedAt}}\nSTATUS:   {{.Status}}\nPORTS:    {{.Ports}}\nNAMES:    {{.Names}}"
terminal
    CONTAINER ID:  157a491d1dc8
    IMAGE:    nginx
    COMMAND:  "/docker-entrypoint.…"
    CREATED:  2023-05-21 18:16:14 +0900 JST
    STATUS:   Up 14 minutes
    PORTS:    0.0.0.0:8080->80/tcp
    NAMES:    vigorous_mclaren

Docker stop

terminal
    docker stop 157a491d1dc8 (container id)
    157a491d1dc8
terminal
    docker ps
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Docker start

If you want to start the same container again, you would execute the "start" command. Running the "run" command would create a new container.

terminal
    docker start 157a491d1dc8 (container id)
    157a491d1dc8

Docker logs

To check the logs, you can execute the following command

terminal
    docker logs 157a491d1dc8

Docker rm

To remove a container, you can use the "rm" command. If you want to remove a running container, you need to include the "-f" option when executing the command.

terminal
    docker rm -f 157a491d1dc8 or 157
0
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
0
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?