Docker
Install Docker Official
| |
Uninstall old versions:
| |
Install from apt repo:
| |
Install Docker Packages:
| |
Setup Docker
Enable running docker commands without the use of sudo:
Check Groups for docker group:
| |
Add if not found:
| |
Add user to docker group:
| |
Configure to start on boot with systemd:
| |
Docker Commands
Docker commands reference can be found here: docker command ref
Stop docker container
| |
remove container
| |
run container
| |
Stop all the containers
| |
Remove all the containers
| |
Enter shell of container
| |
Show images already pulled by docker and stored locally
| |
Start a shell session inside a new ubuntu container -t means terminal -i means interactive:
| |
Enter a shell inside a running container:
| |
Find out which docker compose files created the running container:
| |
Look at docker logs:
| |
Pull down docker container
| |
Run docker container -d runs in detached mode so can use terminal after running -P forwards ports to the container from docker host
| |
inspect the container
| |
Remove container image from host
| |
When running docker containers the run command will require extra options for containers with specific uses. Environment vairables can be added to a document container on startup using a .env file and the switch “–env-file=” in the run command
Docker High CPU usage
See what containers are using system resources:
| |
Check specific container for process:
| |
Check the logs for high cpu use container:
| |
Follow live logs:
| |
restart docker container:
| |
Template docker-compose file Docs
Also see some other templates:awesome-compose github
Inspect Container by namespace
get process id of container:
| |
Info about the namespaces:
- mnt (Mount) - the container has an isolated mount table.
- uts (UNIX Time-Sharing) - the container is able to have its own hostname and domain name.
- ipc (Interprocess Communication) - processes inside the container can communicate via system-level IPC only to processes inside the same container.
- pid (Process ID) - processes inside the container are only able to see other processes inside the same container or inside the same pid namespace.
- net (Network) - the container gets its own set of network devices, IP protocol stacks, port numbers, etc.
- cgroup (Cgroup) - the container has its own virtualized view of cgroups (not to be confused with cgroups themselves).
Copy Files into container
To copy files into/outof a running container use the docker cp command:
| |
Export file system of container
| |
Enable Remote control for docker
Configure the Docker daemon on the remote server to listen on a TCP port. Edit the Docker service file (usually located at /lib/systemd/system/docker.service) to include the following:
| |
Clean Up Overlay files
Check used space:
| |
Clear Unused docker objects:
| |
Check disk usage:
| |
Modify Log management config files:
| |
Completely rebuild docker state:
| |