Docker - Launching a container with an Ubuntu image and useful commands

17.03.2022 | 720 | SQL

Getting and starting the first image and a set of useful commands for working with Docker.

Replace NAME with your name for the container being created.
Installation:
sudo apt install docker docker-compose # install docker & compose
docker pull ubuntu # Download Ubuntu image
Create a new Ubuntu container with mounting the directory to the local:
docker run -it --name NAME --mount type=bind,source=/mnt,target=/var/www ubuntu bash
Create a container for web tests:
docker-compose up -d nginx mysql
View container data:
docker inspect NAME
View the list of running containers:
docker ps
View a list of all created containers:
docker ps -a
Run bash in a container:
docker exec -it NAME /bin/bash
Exporting a container with compression:
docker export NAME | gzip > NAME.gz
Importing a container from an archive:
zcat NAME.gz | docker import - NAME
Delete a container:
docker container rm test
Pull the file out of the container for editing:
docker cp laradock_nginx_1:/etc/nginx/sites-available/symfony.conf .
docker cp symfony.conf laradock_nginx_1:/etc/nginx/sites-available/symfony.conf
Stop, delete all containers:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
MySQL dump creation from a running container
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
MySQL dump loading into the database in a running container
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root
DATABASE


← Back

Comments (0)