- Create and Run a container:
docker run -p <localhost port>:<docker container port> <image-name>
- If you dont want console output:
docker run -d <image-name>
- List Running containers:
docker ps
- List all containers that have run:
docker ps --all
- Restart a stopped container:
docker start <container-id>
- Delete stopped containers and downloaded images:
docker system prune
- Stop a container:
docker stop <container-id>
- Execute additional commands in a running container (other than the starup command):
docker exec -it <container-id> <command>
Eg:docker exec -it <container-id> sh
- Exit from a container:
Ctrl
+d
orexit
- Build a docker image from a
Dockerfile
in current directory:docker build -t <docker-id/project:version> .
- While running a custom built docker image, we can drop the version to run the latest version:
docker run <docker-id/project>
- Dockerfile commands:
FROM WORKDIR COPY RUN CMD EXPOSE # To inform user/ CICD the port to expose
- Build using a dockerfile with custom name
Dockerfile.dev
:docker build -f Dockerfile.dev .
- Mapping current working directory to a directory in the container:
docker run -v $(pwd):/<directory in container> <image-name>
- Mapping
pwd
without mapping an existing directory in the container:docker run -v <existing directory in container> -v $(pwd):/<directory in container> <image-name>
- To prune all images, containers, networks and volumes that are not being used:
docker system prune --volumes
Last active
March 19, 2022 04:46
-
-
Save stephenleo/ce21f75bc0a57c730da5ec4ef6e85302 to your computer and use it in GitHub Desktop.
Docker & Kubernetes
- Scripting DockerCLI commands and Starting up multiple containers with networking
- Run the image defined in
docker-compose.yml
:docker-compose up
- Rebuild the images defined in
docker-compose.yml
:docker-compose up --build
- Run docker compose in the background:
docker-compose up -d
- Stop all containers started up by docker compose:
docker-compose down
- Docker will automatically restart stopped or crashed containers if we add a restart policy to that service:
restart: <'no'/always(eg, for web apps)/on-failure(when exit code !=0, eg, for schedule jobs)/unless-stopped>
- Docker compose ps (only from same working directory as
docker-compose.yml
):docker-compose ps
- Apply a config to kubernetes cluster:
kubectl apply -f <config_file.yaml>
- Get running pods:
kubectl get pods
- Describe any k8s object:
kubectl describe <object-type> <object-name>
- Use
kind: Deployment
instead ofkind: Pod
.Deployment
is inapiVersion: apps/v1
- Get running deployments:
kubectl get deployments
- Delete any k8s object:
kubectl delete -f <config_file.yaml>
- Updating a deployment to pull latest image:
kubectl rollout restart -f <config_file.yaml>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment