docker -v or docker --version both commands show you what version of docker you are running
DOCKER -V OR DOCKER --VERSION
docker -v or docker --version both commands show you what version of docker you are running
DOCKER PS -A
docker ps -a shows all the docker containers
DOCKER PS
docker ps - shows all the running docker containers
DOCKER START
docker start – starts one or more stopped containers.
Running the docker ps command shows no container initially. Running docker start 8612b7d945a4 starts the container named 8612b7d945a4. Running docker ps a second time now shows the container.
DOCKER STOP
docker stop – stops one or more running containers.
Running the docker ps command shows the container named 8612b7d945a4 we started using the docker start. Running docker ps a second time after running docker stop 8612b7d945a4 shows no container.
DOCKER SEARCH
docker search - searches The Docker Hub For Images Example: docker search httpd
You could also search docker hub on the website itself for httpd
DOCKER EXEC -IT "CONTAINER ID"
docker exec -it runs a new command in a running container.
We use the command docker exec -it container id /bin/bash to get a bash shell in a container
We use docker exec -it container id command to execute whatever command you to specify in a container. Let's give you a real example see what it looks like and then execute it.
docker exec -it 4fca8402d798 /bin/bash We use the command followed by bin/bash - to pass the interactive shell in to the container so that we can execute whatever command we specify in the container. root@4fca8402d798 tells us that we are now in our container.
DOCKER RM
docker rm - removes one or more containers Before you can remove a running container you must first stop it.
Use the command below to stop the container: docker stop <CONTAINER ID> docker stop 8612b7d945a4
Followed by the command to remove the container: docker rm <CONTAINER ID> docker rm 8612b7d945a4
After running the <ps -a command> notice that container 8612b7d945a4 no longer exists.
DOCKER RM $(DOCKER PS -AQ)
docker rm $(docker ps -aq) is a docker nested command that deletes all stopped containers at one time.
Running docker ps -a now shows no containers.
DOCKER IMAGE RMI
We can use the docker image rmi command to remove one or more images from your local machine. In this example we will just remove just one image. We run the command: docker image rmi <IMAGE ID> docker image rmi 6e94a98d3442
The docker image was first untagged and then deleted.
As you can see below after running the docker image rm command IMAGE ID 6e94a98d3442 no longer exists.
DOCKER INSPECT
Docker inspect provides detailed information on constructs controlled by Docker such as container, image, volume, network, node, service, or task. We run the command: docker inspect <container id> docker inspect 78cd214a8fa8
By default, docker inspect will render results in a JSON array.
docker inspect -f "{{ .NetworkSettings.IPAddress }}" provides the ip address of a container, We run the command: docker inspect -f "{{ .NetworkSettings.IPAddress }}" followed by the container id
As you can see the ip address of 172.17.0.2 was returned for the container 2e2a62ba0d44
DOCKER PULL
Most of your images will be created on top of a base image from the Docker Hub registry.
Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own.
To download a particular image, or set of images (i.e., a repository), we use docker pull. "docker pull ubuntu" pulls down a base image with Ubuntu.
As you can see it pulled down an base image of Ubuntu and since no tag was given it defaults to a TAG of latest.
PS: Docker will first look on your local machine for the image. If it does not find it locally it will then pull it down from Docker Hub.
DOCKER RUN
The docker run command must specify an IMAGE to derive the container from. docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
docker run -dit 5a3221f0137b
When we first run <docker ps> there are three containers.
After we run <docker run -dit 5a3221f0137b> a new container is created.
Running <docker ps> shows us a fourth newly created container.
It has a CONTAINER ID of <0a9e21605fdb >
It was created from the IMAGE ID< 5a3221f0137b
DOCKER RUN (-p)
We can use docker run and open ports for the host and the container.
<docker run> <--name "you name it"> <-d -p> <8080:80> <"name of image you want to run the container from">
docker run --name web1 -d -p 8080:80 nginx
Where: name = web1 - This is a name that I chose as an example. You can chose your own name for the container.
-d = Running the daemon in the background.
-p = Mapping the ports: The first port 8080 will be the host port. The second port 80 will be the container port. Port 80 on the container will be mapped to port 8080 on the host.
nginx = The name of the image you running the container from.
Go to a web browser and type in localhost:8080 in the url. You now have a running nginx container.
Go to a web browser and type in localhost:8080 in the url. You now have a running nginx container.
DOCKER CP
The docker copy command must specify an IMAGE to derive the container from.
First run <docker ps> to see what containers are active.
Your Subtitle Here
Next I run the docker cp command docker cp <source of file> <container>: <destination of file>
Where:
1.) docker cp is the primary command 2.) / is the source directory of the file (in the host) 3.) 5 is the file name 4.) 0a9e21605fdb is the container name 5.) / is the destination directory (in the container)
docker cp 5 0a9e21605fdb:/
As you can see below the file copied over from the host to the container named 0a9e21605fdb.
DOCKER BUILD
docker build – builds an image from a Dockerfile.
Run the command: <docker build.> docker build followed by the location of your Dockerfile. Dot <.> represents the current working directory and is used in this example.
You can see that all 3 steps that were in the Dockerfile were run and an image id of d10aa382f33c was built successfully.