Docker

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Docker

Running Docker Container


Creating a Docker Image
Docker Compose
Docker Swarm
Networking in Docker

Verison of Linux :- cat /etc/*release*


docker engine
docker
hub.docker.com
kiranjit4u 123hcl***
install :- sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common

Docker Commands :-
docker run ubuntu
docker ps
docker ps -a

Stop a container :-
docker ps
identify the process id of the container
docker stop silly_sammet

Remove a Container :-
docker rm silly_sameet
docker ps -a

List of Images :-
docker images

Remove Images :-
docker rmi ubuntu
--> delete all dependeny containers to remove image.

(So first remove container then you can remove base image.)

Download an Image for future Run command usage :-


docker pull ubuntu

Append a command :-
docker run ubuntu sleep 1000

Execute a command :-
Lets see I want to see a file in a running container.

docker run --help

docker ps --> take the container id or name suppose in this case Container name is
infallible_curie

docker exec infallible_curie cat /etc/hosts


-->docker exec command is used to run anuy command inside the conatiner
docker exec --it <container_id> bash --> now I am inside the container
exit --> to come out from the container.

Demo Docker Commands :-


docker run -it centos bash
--> "-it" option will start centos and then invoke the bash command to start
accepting inputs from user in the form of commands.

docker run -itd centos bash [d --run in backend]

cat /etc/*release*
exit

docker run -d centos sleep 20


docker rm 345 e0a 773 (clean three container by taking first three characters from
the Docker id)

rm --> remove stopped container


if the container is running then use the below command to stop :-

docker rm -f <conatainer_id>

rmi --> remove images

Run a Container 'nginx:1.15-alpine' :-


docker run --name webapp nginx:1.15-alpine sleep 200

To check the Docker Server Version :-


docker version

docker run Ubuntu:17.04 --> to run another ubuntu having version 17.04

docker run mmm/simple-webapp


docker run -d mmm/simple-webapp
docker attach ramunjam
docker run -i mmm/simple-webapp

port mapping
http://172.17.0.2:5000

docker run -p 80:5000 mmm/simple-webapp


-->Port 80 is mapped to 5000

Volumne Mapping
docker run -v /opt/datadir:/var/lib/mysql mysql

Advanced Docker Commands :-

Versioning :-
docker run ubuntu cat /etc/*release*/
what if I run another version of Ubuntu:-
So go to hub.docker and then check for the Supported Tags under ubuntu official
image.

So if we want 17.10 version of ubuntu:-


docker run ubuntu:17.10 cat /etc/*release*

Now it will download and run the version command.


How to keep the container alive for 15 sec:-

docker run ubuntu sleep 15

To run Docker in background:-

docker run -d ubuntu sleep 15


docker ps
docker attach container_id
docker stop container_id
docker run timer

docker run jenkins


access Jenkin in internal ip
open up browser in Docker Host
then use the internal IP of Jenkins.

So where to find this ?


docker inspect container_id_of_jenkins_image
under Network Tag check for the IPAddress

How to access it externally ?


So with docker host ip and then port number of jenkins wont help.
Like this:-
192.64.32.01:8080
So we have to map the jenkin port to Host Ip so that it will listen.
docker run -p 8080:8080 jenkins
now try this from external Ip.

If we want to save the Config of Jenkins in the Container then we have to map the
volume so that we can save the data in another volume for future purpose.

So in order to persist the data like above configuration across container :-


mkdir my-jenkins-data
docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home -u root jenkins
docker network create \
--driver bridge \
--subnet 182.18.0.0/16
custom-isolated-network

You might also like