Wednesday, September 11, 2019

Docker: Executing Container Commands

docker container run -d nginx

docker container ls

docker container run -it nginx /bin/bash

# nginx -g 'daemon off;'

docker container ls

docker container inspect container_id

curl 172.17.0.3


# exit

docker container ls

docker container ls -a

docker container exec -it container_id ls /usr/share/nginx/html
docker container exec -it container_id /bin/bash

# apt-get update -y
# exit

docker container prune

docker container rm -f container_id

===Summary===
Executing a command:
  • Dockerfile
  • During a Docker run
  • Using the exec command
Commands can be:
  • One and done Commands
  • Long running Commands
Start a container with a command:
docker container run [IMAGE] [CMD]
Execute a command on a container:
docker container exec -it [NAME] [CMD]
Example:
docker container run -d -p 8080:80 nginx
docker container ps
docker container exec -it [NAME] /bin/bash
docker container exec -it [NAME] ls /usr/share/nginx/html/