この記事の最終更新日: 2023年4月20日
As a reminder, such as when accessing a server, this article explains how to access a container.
Method for accessing a container using the container ID:
1. Navigate to the directory containing the yml file.
2. Start the container.
// Starting the container
$ docker compose up -d
3. Use “docker ps” to find the ID of the container you want to access.
$ docker ps
// Checking the container
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f8abc5cb320e frontend-project_node "docker-entrypoint.s…" 39 minutes ago Up 38 minutes 0.0.0.0:3000->3000/tcp frontend-project_node_1
2b1de4d894af backend-project_backend "python3 manage.py r…" 56 minutes ago Up 56 minutes 0.0.0.0:8000->8000/tcp backend-project_backend_1
4.「Execute “docker exec -it {ID} sh”.
You can replace “sh” with “/bin/bash” if you prefer.
$ docker exec -it f8abc5cb320e sh
Now you can access the container.
$ /usr/src/app #
Method for accessing a container using the service name:
1. Navigate to the directory containing the yml file.
2. Start the container.
// コンテナ起動
$ docker compose up -d
3.Execute “docker compose exec service_name bash”.
Access the container with the service name “app”.
docker compose exec app bash
Now you can access the container.
$ /usr/src/app #
Differences between docker compose commands and docker commands
大阪のエンジニアが書いているブログ。
コメント