When Do
You Need to Use Docker?
- For replicating the environment on your server, while running your code locally on your laptop
- Experimenting with new things on your laptop without breaking the repositories.
- Creating a production grade environment on you PC with just simple steps.
- For instant testing of your application.
- For Docker CI/CD during numerous development phases (dev/test/QA)
- For distributing your app’s OS with a team, and as a version control system.
Simple ways to setup docker: -
Route
1 (curl required):
# curl
https://get.docker.com | sh
Route
2:
#apt-get update
#apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
#curl -fsSL
https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
#apt-key fingerprint 0EBFCD88
#add-apt-repository \
"deb
[arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
#apt-get update
#apt-get -y install docker-ce
#docker run hello-world
(Note: Use root to
execute Docker commands if you haven’t added your user to the docker group
If you want to add
your user to docker group then:
$ sudo usermod -aG
docker $USER
After this root access will not be required)
How to
use Docker?
- For checking the
number of images on your system, use the following command –
$
docker images
- For searching an
image in the Docker Hub –
$
docker search <image>
- docker pull – Pulls
an image or a repository from a registry
$
docker pull ubuntu
(Note:
By default the tag will be “latest” otherwise you need to specify)
- docker ps – To see
the running or stopped docker containers
$
docker ps -a
- docker run – Creates
and starts a new container according to the supplied attributes.
$
docker run --name containerName –p 8080:80
–it Ubuntu /bin/bash
(Note: 8080
refers to the host port and 80 refers to the container port.
Refer
to https://docs.docker.com/engine/reference/run/
for attribute details and more options)
- docker attach – It
will attach the host terminal to the container terminal
$
docker attach containerName
(Note:
exit command inside the container will stop the container and return to the
host terminal session but if you want to keep the container running then
Ctrl + (p
and q)
- docker start – Starts
one or more stopped containers
$
docker start containerName/Container ID
- docker stop – Stops
one or more running containers
$ docker
stop containerName/Container ID
- docker build – Builds an image form a Docker file
- docker login – Helps
to login to your docker account and then you can push or pull your private
or public Docker images.
- docker push – Pushes
an image or a repository to a registry
- docker export –
Exports a container’s filesystem as a tar archive
- docker exec – Runs a
command in a run-time container
- docker commit –
Creates a new image from a container’s changes
How to create your own Docker Image?
· Create your account on Docker repo site : hub.docker.com
· Create a Repository with some initial description.
· User docker commit to save your running container in your
local repo.
$ docker
commit -m "Apache web server" -a "PrashPlus" 8931afa5aaa6
apacheserver:latest
· Tag your image with the docker Id and your repository name.
$
docker images
Find
your committed image
$ docker
tag bb38976d03cf yourhubusername/apacheserver:latest
· docker push yourhubusername/apacheserver
· Now your required PC run docker pull and you are ready to go.
(Feel free to ask for additional commands or any changes required.)
Big Thanks for this wonderful read. I enjoyed every little bit of reading and I have bookmarked your website to check out new stuff of your blog a must read blog.
ReplyDeleteBest Institute for Cloud Computing in Chennai
Cloud Computing Courses in Chennai
You are most welcome, I will try to keep posting articles...
DeleteThis is good information and really helpful for the people who need information about this.
ReplyDeleteDocker and Kubernetes Training
Docker and Kubernetes Online Training
Docker and Kubernetes Training in Hyderabad
Docker Online Training