Fri, Mar 20, 2020 7:27 PM
Docker is basically a container engine which uses the Linux Kernel features like namespaces and control groups to create containers on top of an operating system and automates application deployment on the container. Docker uses Copy-on-write union file system for its backend storage.
A Docker container is an open source software development platform. Its main benefit is to package applications in containers, allowing them to be portable to any system running a Linux or Windows operating system (OS). A Windows machine can run Linux containers by using a virtual machine (VM).
Here are some basic things like how to install docker and how to we can pull images,build custom image, run containers,remove containers and see the logs, attach volume,inspect the config, etc…
sudo dnf config-manager --add-repo=https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce
sudo systemctl enable docker
sudo systemctl start docker
Search images from registry
using
docker pull
command we can pull the images locally
docker images
command shows the locally builded/downloaed images.
Remove docker images from local cab be done by
docker rmi imagename
Run container by
docker run
commands with Arguments required.
Above
docker
command ran the test_http apcahe container with argument -d -p where -d make sure its run on backgroud and -p to expose port 80,we can verify it using curl localhost:9090 and Good news is it works!
docker cp
command can be used to copy the file to running container.
this below example show command to copy the index.html to running container path /var/www/html
Running containers can be listed using
docker ps
docker ps
only so the running container we can use -a argument to see all the containers [running|stopped]
Kill the running container using
docker kill
command
docker rm
command can be used to remove container
If you would like to remove multiple containers at on shot just run
docker rm $(docker ps -a -q)
Using
docker exec
command we can Run a command in a running container
Using docker exec -it and /bin/bash conainer name we can ssh into container.
by adding VOLUME in docker file we can attach the storage
docker -v path:containerpath
will attach the persistance storage to the container.
docker inspect
command show provides detailed information on constructs controlled by Docker.
Above docker inspect filter show container ip address and next filter show mac address. We can can filter multiple informations.
by writing the Dockerfile we can build the custome image by our wish.
below is the sample Dockerfile
Dockerfile file must start with
FROM
instruction we can add the base image name there.
The
MAINTAINER
instruction allows you to set the Author field of the generated images.
RUN <command>
(shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
COPY
Copies new files or directories from <src> and adds them to the filesystem of the image at the path <dest>.
EXPOSE
Informs Docker that the container listens on the specified network port(s) at runtime.
CMD
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
create a Dockerfile and run docker build command to build the custom image.
docker images
show up the custom buid image. Now we can try running this container.
yes! we can see the container running and the index.html file we copied while build shows up.
Run the mysql container mysql-57-centos7 docker registry image.
find the network details of the container and connect the db and verify.
container
docker
Learning