Difference between revisions of "Docker commands"

From Tech-Wiki
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Linux]]
 
[[Category:Linux]]
 
After installing Docker, remember to configure the service to automatically start
 
chkconfig docker on ; systemctl enable docker ; service docker start
 
  
 
Add your docker user to the docker group:
 
Add your docker user to the docker group:
Line 8: Line 5:
  
 
In order to create one container via CLI this command below will be the equivalent of the compose file further below.
 
In order to create one container via CLI this command below will be the equivalent of the compose file further below.
  # docker create \
+
  docker create \
 
   --name=webserver --net=host -e VERSION=latest \
 
   --name=webserver --net=host -e VERSION=latest \
 
   -e PUID=$(id -u docker) -e PGID=$(id -g docker) \
 
   -e PUID=$(id -u docker) -e PGID=$(id -g docker) \
 
   -v /var/www/html:/app:ro \
 
   -v /var/www/html:/app:ro \
 
   --restart unless-stopped nginx
 
   --restart unless-stopped nginx
  # docker start nginx
+
  docker start nginx
  
 
docker-compose.yaml
 
docker-compose.yaml
Line 25: Line 22:
 
     restart: always
 
     restart: always
 
     network_mode: host
 
     network_mode: host
 +
 +
If using the compose file above, the container can be executed using:
 +
docker-compose up -d
 +
 +
In order to monitor the status of running containers, run:
 +
docker stats
 +
 +
In order to monitor performance of processes inside a container, run:
 +
docker top container1
 +
 +
If you need to get rid of all images:
 +
docker system prune -a
 +
 +
In order to troubleshoot the container, you can attach to a shell using:
 +
docker exec -it webserver /bin/bash

Latest revision as of 14:05, 9 January 2024


Add your docker user to the docker group:

usermod -a -G docker ec2-user

In order to create one container via CLI this command below will be the equivalent of the compose file further below.

docker create \
  --name=webserver --net=host -e VERSION=latest \
  -e PUID=$(id -u docker) -e PGID=$(id -g docker) \
  -v /var/www/html:/app:ro \
  --restart unless-stopped nginx
docker start nginx

docker-compose.yaml

version: '2'
services:
 myproject:
   container_name: webserver
   build: ./
   volumes:
     - /var/www/html:/app
   restart: always
   network_mode: host

If using the compose file above, the container can be executed using:

docker-compose up -d

In order to monitor the status of running containers, run:

docker stats

In order to monitor performance of processes inside a container, run:

docker top container1 

If you need to get rid of all images:

docker system prune -a

In order to troubleshoot the container, you can attach to a shell using:

docker exec -it webserver /bin/bash