Running rabbitMQ docker container

docker run -d –hostname my-rabbit –name rabbitmq -p 8080:15672 -p 5672:5672 rabbitmq:3-management

–host name – name of host

–name – name of container

— p – forward port from docker container to local machine

using reabbimq:3-management to access web console to manage rabbitMQ console


Running redis using docker container

docker run -it -d –name redis -p 6379:6379 -v $PWD/data:/data redis redis-server –appendonly yes

-v – to map local volume to container for persistence
–appendonly – for persistance

accessing container

docker exec -it redis /bin/bash

Few commands to run Docker containers

Installing docker on MAC

brew install docker

Get docker info

Docker info

Run Container with docker “hello world!”

docker run hello-world

docker run -it alpine  – run alpine distro of linux

docker run -it ubuntu – run ubuntu distro of Linux

Pull docker image from hub repository

docker pull [image name]:[tag]

docker pull [private registry url]/[image name]:tag – to pull from private docker registry

Login/logout from docker repository

Docker login – to login default repository

docker login URL – to login to private repository

docker logout – to logout

Docker image commands

FROM – Create docker image from base Docker image

RUN – run command in a docker container

WORKDIR – setup working directory

COPY – copy local content to docker image

LABEL – Add metadata to docker image, such as maintainer, version etc.

CMD – run Command when the docker image is built

Building docker image

docker image build . -t [image name]

docker image inspect [image name]

Push docker image to a registry

docker image push [image name]

Run docker container

Docker container run -it -p [localport]:[container port] -e [parameter name]=[param value] –rm –name [container name] -d –restart on-failure -v [local volume]:[container volume] -w [working directory inside container] [docker image name]

-it = enable to

-p = port two port separated by column localport:container port

-e = environment variable

–rm = remove inactive container

–name = [name] name the container

-d – detached mode

–restart on-failure – docker container restart automatically on failure

–env-file list – environment file list

-h –hostname container hostname

-i –interactive – keep STDIN open even if not attached

-l –label-list – set meta data on a container

 –label-file set

-m –memory memory limit

-P – published all exposed port to random ports

-u –user user name or UID

-v –volume bind mount a volume

-w –workdir working directory inside the container

List of docker images and container

docker images – to get a list of images

docker container ls – to get a list of containers

docker volumes ls – to get a list of volume

docker network ls – get a list of networks

Shrink docker container size

docker system prune – to remove unused containers

docker system prune -a – to remove containers as well as not used images