Post Thumbnail

Docker containers for dummies

By the team at Turnkey Tech, Oct 18, 2019

Docker allows you to package an application with all of its dependencies into a standardized unit for software development. More than that, Docker is a popular tool to make it easier to build, deploy and run applications using containers.

Why should you use Docker?

  • Try any other version of OS in few seconds without uninstalling existing OS
  • Save installation time on new machines: Install libraries, frameworks inside docker and use that image on any other machine
  • Version compatibility: Since all libraries will be inside docker which is like a separate machine hence no version mismatching

How to use Docker?

Switch to “root” user or run all below command with “sudo” prefix as docker daemon needs “sudo” permission to run

Install docker

apt-get install

Pull docker image from Docker Hub.

Sample image in which I installed python, I built it upon the official Ubuntu image.

docker pull [image name]

List all available docker images in your system

docker images [image name]

Build a container out of docker image

docker run -it [image name:tag] or [image id] bash[image name]

List Containers

List all running containers:

docker ps

List latest created running container

docker ps -l

List all containers which are created(Need not be running)

docker ps -a

Close a running container

docker stop [container id]

Restart a closed container

docker start [container id]

Go to the terminal of a running container

docker exec -it [container id] bash

Modify your container: Install libraries

Here I installed python

apt-get update
apt-get install python

Save container to an image

docker commit [container id] [give image name:give new tag]

Push the changes to docker hub

Create a docker hub account if you don’t have and login to that using terminal

docker login -u [username]
[Enter password]

Create tag: Can be anything

docker tag [image name:tag] [docker hub username]/[image name:tag]

Push docker image to DockerHub

docker push [docker hub username]/[image name:tag]

Finally, pull this image on any other machine and enjoy coding python without reinstalling python into it. Likewise, you can build Docker images on your machine and can reuse those images anywhere and get rid of the pain of reinstalling modules/ libraries every time.

Thanks! for reading. Please reach out to any queries.

Connect PC To Phone..

    Prev Post

Neural Compute Stick (NCS)..

Next Post