Thursday, November 2, 2023

Docker

#docker version

If you get a output from the Client and Server, your command run successfully, if you get error then run with sudo command after add your user account to the local docker group,

#docker images

Its like OS template.

docker pull centos:latest

Download images onto your Docker host is called pulling. Pull the ubuntu:latest image. 

Now run docker images command to show your download images.

#docker run -it centos:latest /bin/bash

It will check centos images locally not available then download from dockerhub and start container in interactive mode with bash shell and login in container terminal.

Press Ctrl-PQ

Its exit from container without terminating it.

# docker exec -it App1(Container Name) bash

# docker exec -it 851464 or (Container id) bash

Attaching to running containers login

# docker run kodecloud/simple-webapp

This docker running in foregroup means you cant do anythisng on terminal

# docker run -d kodecloud/simple-webapp ( -d Deteached mode)

This docker running in background means you can use this terminal.

# docker attach container id


# docker rm (container id)

docker container remove by container id

# docker rm (container name)

docker container remove by name

# docker container prune

This will remove all stopped containers

# docker rmi 81464

Remove docker images

# docker rmi -f 81464

Remove docker images forcefully

#  docker ps -a 

show all container which is running and stop

# docker run -p 8080:80 nginx

Where the first 8080 is the local port and the second 8080 is the container port.

Port mapping

# docker run -v /opt/datadir:/var/lib/mysql mysql

Volume Mapping

# docker logs container name or id (strange_wing)

Check container logs

# docker inspect container name or id (lucid_rhodes)

Check container configuration

# docker run ubuntu

# docker run ubuntu --network=none

# docker run ubuntu --network=host


# docker netowrk create \

--driver bridge

--subnet 182.18.0.0/16

custom-isolated-network


# docker network ls

# docker inspect dockername or id

Embedded DNS


/var/lib/docker

aufs

containers

image

volumes


Layered architecture


# docker build dockerfile -t ritesh/my-custom-app


# docker run ritesh/my-custom-app


Volume Mounting


# docker volume create data_volume


/var/lib/docker

volumes

data_volume


# docker run -v data_volume:/var/lib/mysql mysql

# docker run -v data_volume2


Binding Mount ( Mount Directory)


A directory any location any


Storage Drivers


AUFS

ZFS

BTRFS

Device Mapper

Overlay

Overlay2

No comments:

Post a Comment