- How do you build a Docker image from a Dockerfile?
docker build -t myimage:1.0 .
- How do you run a Docker container in the background and expose a port?
docker run -d -p 8080:80 myimage:1.0
- How do you mount a host directory as a volume in a Docker container?
docker run -v /path/on/host:/path/in/container myimage:1.0
- How do you create a Docker network?
docker network create mynetwork
- How do you attach a Docker container to a network?
docker network connect mynetwork mycontainer
- How do you see the logs for a Docker container?
docker logs mycontainer
- How do you stop a Docker container?
docker stop mycontainer
- How do you start a stopped Docker container?
sqlCopy codedocker start mycontainer
- How do you execute a command inside a running Docker container?
docker exec mycontainer ls -l
- How do you create a Docker image from a running container?
docker commit mycontainer myimage:2.0
- How do you push a Docker image to a Docker registry?
docker push myregistry/myimage:1.0
- How do you pull a Docker image from a Docker registry?
docker pull myregistry/myimage:1.0
- How do you list all the Docker containers running on your system?
docker ps
- How do you remove a Docker container?
docker rm mycontainer
- How do you remove a Docker image?
docker rmi myimage:1.0
- How do you inspect a Docker container?
docker inspect mycontainer
- How do you create a Docker volume?
docker volume create myvolume
- How do you attach a Docker volume to a container?
docker run -v myvolume:/path/in/container myimage:1.0
- How do you copy a file from the host to a Docker container?
docker cp myfile.txt mycontainer:/path/in/container
- How do you copy a file from a Docker container to the host?
docker cp mycontainer:/path/in/container/myfile.txt .