Docker commands
- Version, Info …
>docker version
>docker info
- Search
Searches images in docker registry.
docker search <Image Name>
>docker search ubuntu
- Images
List all the downloaded images
>docker images
>docker ps –a
-a – show all
-l – show last
- Pull
Pulls the image if it is not available locally. It runs automatically by docker run.
>docker pull <Image name>
- Run
Docker run starts the container by giving the image name a process to run in that container. The container stops when the main process stops. It automatically pulls the image.
>docker run –ti <image>:[<version/latest>] <program to run>
-ti – terminal interactive
-d – detach – will run in the background
-c – command
-p – port. eg. –p 1234:3456 Expose port 1234 on the inside of the container to the outside of container as port 3456.
docker run –p <outside-port>:<inside-port>/protocol(tcp/udp)
-v – volume
docker run –v <path in host>:<inside the container path>
>docker run –ti –v /home/docker/example:/shared-folder ubuntu bash
--name – name of the container
--memory – maximum allowed memory
--cpu-shares – relative to other containers
--cpu-quota – limit it
--link <Name of container> – for communication between two containers. It automatically assigns a hostname. Link can break when containers restart.
--net==<Network name>
--volumes-from <Name of the container that we want to use the volume> – To share data/file between containers.
- Commit and Tag
>docker commit <id of the container>
Tagging gives images names
>docker tag <id received from commit> <Image/Tag name>
or
>docker commit <Name of the container> <Image/Tag name>
- Build
Creates an image for the docker file
>docker build –t <Name of tag> .
The (.) shows the docker file in here. Otherwise need to pass the path of docker file.
- Push
Upload a tagged image to docker hub
>docker push <Tag name>
- Attach
>docker attach <Container name>
- Exec
>docker exec
Starts another process in an existing container.
- Logs
Docker logs keep the output of the container.
>docker logs <Container name or ID>
- Stopping and Removing
>docker kill <Container name/ID>
>docker rm <Container name/ID>
- Network
>docker network create <Network name>
- Clean Up
>docker rmi <Image name/Image ID>:<Tag>
- Login
Login in to docker hub
No comments:
Post a Comment