Skip to content

huiminlim/dockerinaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Docker in Action

Getting Started

Install Docker Engine by following instructions here.

Run the command to check that Docker Engine is working correctly.

sudo docker run hello-world

Follow the instructions here to run Docker without sudo.

Common Commands

Running a container from image, detached to background. The container will be running automatically.

To run the programs interactive, use the -it flag.

To delete container after finishing run, use the --rm flag.

docker run --detach --name webcontainer nginx:latest

However, to create a container from an image but in stopped state, use the create command.

docker create --name webcontainer nginx:latest
docker start webcontainer

To check actively running containers, run the ps command.

docker ps

Containers can be restart and verified to be restarted correctly.

docker stop webcontainer # Stops the container
docker restart webcontainer
docker logs webcontainer

To run additional programs in a docker container, use the exec command.

docker exec webcontainer ls # Runs the ls command inside webcontainer

Images

To pull an image only rather than spin containers up, use the pull command.

docker pull nginx:latest
docker pull quay.io/dockerinaction/ch3_hello_registry:latest # from alternate sources not from docker hub

To save the image as a tar file, use the save command. Then, load it using the load command.

docker save -o nginx.tar nginx:latest
docker load –i nginx.tar

A docker image can also be built using a dockerfile.

docker build -t test:latest ch3_dockerfile # ch3_dockerfile is a directory containing the Dockerfile

Images can be deleted using the rmi command.

docker rmi test:latest

Volumes

There are 2 types of volumes in Docker: Bind mounts and Docker-managed volumes.

alt text

Bind Mount volumes are useful to share data across processes.

The -v flag is used to create a mapping: key is the path on the host and value is absolute path to container location.

docker run -d --name bmweb -v ~/example-docs:/usr/local/apache2/htdocs -p 80:80 httpd:latest

About

Docker in Action

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published