[docker-compose up] Running Docker
[docker-compose up -d] Running Docker on the background
[docker info] shows general docker information
[docker container run -it -p 80:80 nginx] creates a container pulling nginx from docker hub
[docker container ls -a] shows running and non running containers
[docker image ls -a] shows running and non running images
[docker containter rm <first 3 id characters>] removes a container but keeps an image
[docker image rm <first 3 id characters>] removes an image
[docker ps] shows only running docker containers
[docker container stop <containerName>] stops running container name
[docker container exec -it <containerName> bash] runs container
[cd usr/share] normaly where images are stored localy
[docker container run -d -p 8080:80 -v $(pwd):/usr/share/nginx/html --name nginx-website nginx] creates a new container called nginx-website with the original image files stored locally on dir /usr/share
[docker system prune -a] To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:
[docker-compose exec -it containerName bash] runs conteiner in bash mode, normaly is app
[docker volume ls] Shows docker volumes (DB)
[docker volume rm] Removes a docker volume (DB)
[docker build imageName (i.e. mysql)] updates an image of a container (container must be down first and up after build)
[docker system prune --volumes] removes all unused volumes
[docker run -it container] runs a container and enters a terminal
[docker run -p 80:5000 container] Allows access to a container through the host: http://192.168.1.50:80 -> http://172.17.0.2:5000 (Docker internal IP and Port)
[docker run -v /opt/datadir:/var/lib/mysql mysql] Maps a docker container directory to a local directory in the host
[docker inspect container] Shows the configuration of a container
[docker logs container] Shows the logs of the container
[docker attach containter_id] Attaches to a running container
[docker build .] Builds the image from the Dockerfile document
[docker build -t image_name:tag] Bilds an image with a name and tag
[docker run image cat /etc/*release*] runs an image and executes after, in this case shows the OS version
[docker run -p 38282:8080 --name blue-app -e APP_COLOR=blue -d simple-webapp] runs a simple-webapp container and names it blue-app with an environment variable
[docker exec -it blue-app env] executes the running container and shows the env variables
[docker run ubunto sleep 5] runs latest ubuntu image and executes a command after starting the container
[docker run --entrypoint sleep2.0 ubuntu-sleeper 10] runs the ubuntu-sleeper container and adds the entry point sleep2.0, 10 is appended
[docker network ls] displays the active docker networks available
[docker run --name alpine-2 --network=none alpine] Run a container named alpine-2 using the alpine image and attach it to the none network.
[ocker network create --driver bridge --subnet 182.18.0.1/24 --gateway 182.18.0.1 wp-mysql-network] Create a new network named wp-mysql-network using the bridge driver. Allocate subnet 182.18.0.1/24. Configure Gateway 182.18.0.1
[docker run -d -e MYSQL_ROOT_PASSWORD=db_pass123 --name mysql-db --network wp-mysql-network mysql:5.6] Deploy a mysql database using the mysql:5.6 image and name it mysql-db. Attach it to the newly created network wp-mysql-network
[docker run --network=wp-mysql-network -e DB_Host=mysql-db -e DB_Password=db_pass123 -p 38080:8080 --name webapp --link mysql-db:mysql-db -d kodekloud/simple-webapp-mysql] Deploy a web application named webapp using the kodekloud/simple-webapp-mysql image. Expose the port to 38080 on the host.
The application makes use of two environment variable:
1: DB_Host with the value mysql-db.
2: DB_Password with the value db_pass123.
Make sure to attach it to the newly created network called wp-mysql-network.
[docker exec -it mariadb101 tail -f /var/lib/mysql/general.log] views live sql logs for dockerized old version of controlspa