docker version
docker ps
List all running containers
docker ps --all
List of all of containers we have ever created
docker run hello-world
docker run
= docker create
+ docker start
docker create hello-world
Shows the id of the container that is just created
docker start -a <container id>
Executes the hello-world inside this container
-a
means attach to the container and watch out of the container and
print the output of the container
docker logs <container id>
docker create hello-world
docker start <container id>
docker logs <container id>
docker system prune
To see that it was deleted:
docker ps --all
docker run busybox echo hi there
docker run busybox echo buy there
docker run busybox ls
<-- prints all the files and folders inside the
given directory
docker run busybox ping google.com
docker create busybox ping google.com
docker start <container id>
docker logs <container id>
docker ps
docker stop <process id from docker ps command>
<-- has 10 seconds
to shut down gracefully. After that docker kill it
docker start <process id from docker ps command>
docker kill <process id from docker ps command>
Execute an additional command in a container
docker exec -it <container id> <command>
Same asdocker exec -i -t <container id> <command>
docker
- reference the Docker clientexec
- run another command-it
- allow us to provide input to the container<container id>
- id of the container<command>
- command to execute-i
- attach our terminal to the STDIN channel of the running process
(here redis-cli). Any staff that i type gets directly into STDIN of redis-cli
-t
- show things pretty formatted
docker run redis
docker ps
docker exec -it <container id> <command>
docker exec -it <container id> redis-cli
ORwinpty docker exec -it <container id> redis-cli
set myvalue 5
get myvalue
Example: Docker with Redis
docker run redis
docker ps
docker exec -it <container id> sh
<--- sh is a shell ORwinpty docker exec -it <container id> sh
docker run -it busybox sh
ping google.com
echo my message
mkdir redis-image
cd redis-image
code .
<-- starts Visual Code editor
# Use and existing docker image as a base # Download and install a dependency # Tell the image what to do when it starts as a container
# Use and existing docker image as a base FROM alpine # Download and install a dependency RUN apk add --update redis # Tell the image what to do when it starts as a container CMD ["redis-server"]
docker build .
docker run <image id>
docker build -t <your docker id>/<Repo / Project name>: <latest or version number> <. or directory of files/folders to use for the build >
docker build -t rayalevinson/redis:latest .
docker run rayalevinson/redis
docker run -it alpine sh
winpty docker run -it alpine sh
apk add --update redis
docker ps
docker commit -c 'CMD ["redis-server"]' CONTAINERID
If you are a Windows user you may get an error like "/bin/sh: [redis-server]: not found" or "No Such Container" see below
docker commit -c "CMD 'redis-server'" CONTAINERID
docker run CONTAINERID
docker container run -d -p 8081:80 --name myapache httpd
$ docker image build -t nginx-website