194 total views, 1 views today
If you are a beginners in docker, then you have to Below are the basic commands for docker
For pull the docker image
# docker pull image:tag
Note: If you not mentioned the tag, then it will automatically pick the “latest” tag.
so the command looks like below
# docker pull ubuntu:latest
Show docker images
# docker images
This will show you all images that you have pulled in your local repository.
Build an image from DockerFile
# docker build -t <newimagename:tag> .
Run a container from docker image
# docker run --publish=80:80 --name=<anyname> <docker-image-name:tag>
Below are the command explain:
- –publish – You can see two port are mentioned in this arguments by separate with “:”. First one indicates that what port will use in your host pc and second port indicates what port you want to use in your docker container. You can expose any available port here.
- –name – Put your docker container name here.
- You have to mentioned the docker image name with the tag here.
So the commands look like below
# docker run --publish=80:80 --name=test-server ubuntu:latest
Run a container from docker image with privilege
By default, Docker containers are “unprivileged” to run a Docker daemon inside a Docker container. This is because by default a container is not allowed to access any devices, but a “privileged” container is given access to all devices
# docker run --publish=80:80 --privileged --name=test-server ubuntu:latest
When you give –privileged, Docker will enable access to all devices on the host.
Take image from a running container
# docker commit <containerID> <newimagename:tag>
This will take a image from a running container
Stop a running container
# docker stop <containerID>
Start a stopped container
# docker start <containerID>