Docker-Compose Kill / Port / Exec / Run / Restart / Pull
docker-compose kill
command use to kill the container
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8000->80/tcp
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8002->80/tcp
[email protected]:~/docker-compose$ docker-compose kill
Killing docker-compose_webapp1_1 ... done
Killing docker-compose_webapp2_1 ... done
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Exit 137
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Exit 137
[email protected]:~/docker-compose$
docker-compose port
command is use to see the mapping of container ports. Command tells about on which port of host, the container port is mapped. The below command shows that port 80 of the webapp1 container is mapped to port 8000 of the host.
[email protected]:~/docker-compose$ docker-compose start
Starting webapp1 ... done
Starting webapp2 ... done
[email protected]:~/docker-compose$ docker-compose port webapp1 80
0.0.0.0:8000
[email protected]:~/docker-compose$
docker-compose logs
is the command to see the container logs.
gaurav@learning-ocean:~/docker-compose$ docker-compose logs
Attaching to docker-compose_webapp1_1, docker-compose_webapp2_1
webapp2_1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
webapp2_1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
webapp2_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
.....
if you want logs continually from containers then use -f
[email protected]-ocean:~/docker-compose$ docker-compose logs -f
docker-compose exec
the command is use to run any command inside, docker exec does not create a new container to run any command ,it will run it on running containers.
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8000->80/tcp
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8002->80/tcp
[email protected]:~/docker-compose$ docker-compose exec webapp1 ls
bin docker-entrypoint.d home media proc sbin tmp
boot docker-entrypoint.sh lib mnt root srv usr
dev etc lib64 opt run sys var
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8000->80/tcp
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8002->80/tcp
[email protected]:~/docker-compose$
docker-compose run
docker-compose run command will create a new container and then runs the command inside it.
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8000->80/tcp
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8002->80/tcp
[email protected]:~/docker-compose$ docker-compose run webapp1 ls
Creating docker-compose_webapp1_run ... done
bin docker-entrypoint.d home media proc sbin tmp
boot docker-entrypoint.sh lib mnt root srv usr
dev etc lib64 opt run sys var
[email protected]:~/docker-compose$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
acc6ef6c3366 nginx "/docker-entrypoint.…" 32 seconds ago Exited (0) 31 seconds ago docker-compose_webapp1_run_240e22a09a9f
aa9371ae4c98 nginx "/docker-entrypoint.…" 25 minutes ago Up 9 minutes 0.0.0.0:8000->80/tcp docker-compose_webapp1_1
225a77fbc32b nginx "/docker-entrypoint.…" 25 minutes ago Up 9 minutes 0.0.0.0:8002->80/tcp docker-compose_webapp2_1
[email protected]:~/docker-compose$
What is the Difference between docker-compose exec and docker-compose run Command?
the command is used to run any command inside, docker exec does not create a new container to run any command, it will run it on running containers, whereas the docker-compose run command will create a new container and then runs the command inside it.
docker-compose restart
will restart the container
[email protected]:~/docker-compose$ docker-compose restart
Restarting docker-compose_webapp1_1 ... done
Restarting docker-compose_webapp2_1 ... done
[email protected]:~/docker-compose$
docker-compose pull
will pull the images(that we are using docker-compose.yaml) from the repository
[email protected]:~/docker-compose$ docker-compose pull
Pulling webapp1 ... done
Pulling webapp2 ... done
[email protected]:~/docker-compose$