Docker Documentation
Docker is a tool designed to make it easier to create, deploy, and run applications by using
containers. Containers allow a developer to package up an application with all of the parts it needs,
such as libraries and other dependencies, and ship it all out as one package.
Installing Docker on Linux
$ curl https://get.docker.com > /tmp/install.sh
$ cat /tmp/install.sh
...
$ chmod +x /tmp/install.sh
$ /tmp/install.sh
Write a simple program in the main terminal and create the .bin file and excecute it.
Running Your First Image
$ sudo docker run --name <containername> -it ubuntu
$ sudo docker run --name sample -it ubuntu
after using this command we enter into the interactive terminal
root@0cbebaa72623:/#
To copy the file or program from main terminal use the following command
$sudo docker cp <programname> <root_id>:/dir/
$sudo docker cp hello_world.c 0cbebaa72623:/home/
Command to List containers and get the container id
$ sudo docker ps -a
We can build an image using two methods
1. By commiting
Command to commit
$sudo docker commit <container id> repository:tagname
To run the image get image id using the command
$sudo docker images
$sudo docker run -it <image id>
We enter into the interactive terminal and now we can execute the program
2.By creating a Dockerfile
$ vi Dockerfile
script
FROM repository:tagname
CMD <path ./home/ >
save the docker file and command to build it
$sudo docker build -t repository:tagname .
$sudo docker images
$sudo docker run -it <image id>
To save docker logs to a file
Edit the Dockerfile
$ vi Dockerfile
NOTE: We need to create new repository, tagname and container name to
save the logs
build the Dockerfile
$ sudo docker build -t repository:tagname .
run the Dockerfile
$ sudo docker run --name <container name> -it <image id>
save docker log to file
$ sudo docker logs <containername>
$ sudo docker logs <container name> > <file name>
Now to see the output open the file
$ vi <filename>