Current Status

Actively playing with all possible backend services

10 August, 2018

My Docker learning short notes

I had this note from long time in my Evernotes, I thought I should have post it here, so someone might find it useful.

Why docker?

Containerization! Running applications in containers instead of virtual machines.
Dockers are not VMs. Different benefits. One of the main advantages to a Docker-based architecture is standardisation. Also it ensures Continuous deployment  from development to production with CI efficiency to (build a container image and) use  same image across every step of the deployment process.

Pros:
Self contained
Isolated environment
Runs almost everywhere(specially in the Cloud)
Small and lightweighted
Very scalable

Commands:

Get the version
$ docker --version
or
$ docker -v
$ docker-compose --version
$ docker-machine --version

$ docker run hello-world
$ docker run -d -p 80:80 --name webserver nginx
http://localhost/
$ docker container ls
$ docker container stop webserver
$ docker container ls -a
$ docker container rm webserver
$ docker image ls
$ docker image rm nginx

What is an image?

An image is an executable package that includes everything needed to run an application--the code, a runtime, libraries, environment variables, and configuration files.

What is an Container?

A container is a runtime instance of an image--what the image becomes in memory when executed (that is, an image with state, or a user process).

Dockerfile?

Portable images are defined by something called a Dockerfile

We can create a file called Dockerfile (contents differ).
To create a Docker image run the build command with tag using -t so it has a friendly name.

$ docker build -t friendlyhello .

To run the app, mapping your machine’s port 4000 to the container’s published port 80 using -p:

$ docker run -p 4000:80 friendlyhello
docker build -t friendlyhello .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello  # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello         # Same thing, but in detached mode
docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running
docker container stop            # Gracefully stop the specified container
docker container kill          # Force shutdown of the specified container
docker container rm         # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers
docker image ls -a                             # List all images on this machine
docker image rm             # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag username/repository:tag  # Tag for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry
docker logs containerName #check logs related to one container
docker stack ls                                            # List stacks or apps
docker stack deploy -c   # Run the specified Compose file
docker service ls                 # List running services associated with an app
docker service ps                   # List tasks associated with an app
docker inspect                    # Inspect task or container
docker container ls -q                                      # List container IDs
docker stack rm                              # Tear down an application
docker swarm leave --force      # Take down a single node swarm from the manager

Multi-container, multi-machine applications are made possible by joining multiple machines into a “Dockerized” cluster called a swarm. A swarm is a group of machines that are running Docker and joined into a cluster.


go inside container:
docker exec -it {id or name} sh
docker exec -it {id} bash

Getting IP address of docker container running:
docker container ls
docker inspect | grep "IPAddress"

2 comments:

Bhanu Sree said...

Great blog!! Thanks for sharing
Kubernetes Online Training
Docker Online Training
Docker Training in Hyderabad

Joyal said...

Good post and informative. Thank you very much for sharing this good article, it was so good to read and useful to improve my knowledge as updated, keep blogging. Thank you for sharing wonderful information with us to get some idea about that content.
oracle training in chennai

oracle training institute in chennai

oracle training in bangalore

oracle training in hyderabad

oracle training

oracle online training

hadoop training in chennai

hadoop training in bangalore


Some Popular Posts