Docker
Commands
Create a user-defined
network
docker network create --driver bridge <network-name>
To remove a network:
docker network rm <network-name>
Start container & force rebuild
docker-compose up --build <service>
Manage service state
docker start <service>
docker stop <service>
docker rm <service>
docker rm -f <service>
Get container details
docker inspect -f
Images
Image prune
docker image prune --filter="label=deprecated"
docker image prune --filter="label!=down=deprecated"
Containers
Shell access to container
Debian
docker exec -it <container> /bin/bash
Alpine
docker exec -it --user root <container> sh
Copy file between host & container
docker cp <container>:/path/to/file.ext .
docker cp ./file.ext <container>:/path/to/file.ext
Containers - MySQL
Connect to database instance
mysql -u root -p
Create new database user
CREATE USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON *.* TO 'username'@'%';
FLUSH PRIVILIGES;
Export database dump file
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
Restore database dump file
docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE < backup.sql
Enable ONLY_FULL_GROUP_BY
\sql
\connect root@localhost
SET sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY',''));
docker-compose.yml
extends
services
Service properties can be overridden in the location that it was extended in.
env_file
Respective .env
file is loaded from the context in which docker-compose
command is run. If a
service is extended, properties defined in its own .env
file, must also be defined in the .env
file where it is extended.
networks
Any defined networks is an extended service must also live where it was extended.
Define top-level variables
dev.database-env:
KEY: value
services:
service-name:
environment:
<<: *database-env
Daemon WSL 2
Limit resources used by Docker daemon using WSL 2
Create .wslconfig
config file:
%USERPROFILE%/.wslconfig
[wsl2]
memory=1GB
swap=1GB
processors=1
Restart WSL service:
Restart-Service LxssManager