You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run conatiner and drop to shell docker run -it <image> Full form docker run --interactive --tty <image>
Run a container in background docker run -d <image>
Set container restart settings docker run --restart (always|no|on-failure[:maxretries]|unless-stopped) <image>
Start an exited container docker start <name>
Remove a container when exited docker run -rm <image>
Provide container nickname docker run --name <name> <image>
2. Accessing containers
Run commands inside a contaner docker exec <name> <command>
e.g. docker exec test_container ps-aux
Log into a shell inside a container to run more complex commands docker exec -it <container_name> <shell_name> Example for running bash shell: docker exec -it test-container bash
Copying file from the container docker cp <container_name>:<path> <to_path> Example for copying nginx config from a container: docker cp default.config nginx-container:/etc/nginx/conf.d/default.conf .
3. Container management
Stop container docker stop <name>
e.g. docker stop test_container
Remove container docker rm <name>
e.g. docker rm test_container
Remove all stopped containers docker container prune
Rename a container docker rename <old_name> <new_name>
Get stats for container like CPU info etc docker stats <container_name>
Get detailed info about a container like public ip adress etc docker inspect <container_name>
Save container as an image to used later on docker commit <container_name> <image_name>
Important command to map container port to host server docker run -p <host_port>:<container_port> <container_image>
4. Image management
Pull remote image docker pull <image-name>
e.g. docker pull alpine
Show all images pulled already docker image ls
Remove image docker image rm <image-name>
Remove problematic images docker image prune
Remove images not linked to a container docker image rm <image-name>
View image information docker image inspect <image-name>
5. Pushing image to docker hub
Log in to your Docker account on the CLI. docker login --username=<username>
Tag the image with the repo name. docker tag <image> <username>/<reponame>
Push the image to Docker Hub. docker push <username>/<reponame>