❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Docker Ep 12 – Cheatsheet

19 August 2024 at 01:27

Here’s a Docker cheat sheet that covers the most commonly used Docker commands, organized by categories.

Docker Basics

  • docker --version: Show the Docker version installed on your system.
  • docker info: Display system-wide information, including Docker version, number of containers, and images.
  • docker help: Get help on Docker commands.

Docker Images

  • docker images: List all Docker images on your system.
  • docker pull <image>: Download an image from a Docker registry (e.g., Docker Hub).
  • docker build -t <image_name> .: Build an image from a Dockerfile in the current directory and tag it with a name.
  • docker tag <image_id> <new_image_name>: Tag an image with a new name.
  • docker rmi <image>: Remove one or more images.
  • docker history <image>: Show the history of an image (layers).

Docker Containers

  • docker ps: List all running containers.
  • docker ps -a: List all containers (running and stopped).
  • docker run <image>: Run a container from an image.
  • docker run -d <image>: Run a container in detached mode (in the background).
  • docker run -it <image>: Run a container in interactive mode with a terminal.
  • docker run -p <host_port>:<container_port> <image>: Map a port from the host to the container.
  • docker stop <container>: Stop a running container.
  • docker start <container>: Start a stopped container.
  • docker restart <container>: Restart a running container.
  • docker rm <container>: Remove a stopped container.
  • docker logs <container>: View the logs of a container.
  • docker exec -it <container> <command>: Execute a command inside a running container (e.g., bash to open a shell).

Docker Networks

  • docker network ls: List all Docker networks.
  • docker network create <network_name>: Create a new Docker network.
  • docker network inspect <network_name>: View detailed information about a network.
  • docker network connect <network_name> <container>: Connect a container to a network.
  • docker network disconnect <network_name> <container>: Disconnect a container from a network.
  • docker network rm <network_name>: Remove a Docker network.

Docker Volumes

  • docker volume ls: List all Docker volumes.
  • docker volume create <volume_name>: Create a new Docker volume.
  • docker volume inspect <volume_name>: View detailed information about a volume.
  • docker volume rm <volume_name>: Remove a Docker volume.
  • docker run -v <volume_name>:<container_path> <image>: Mount a volume inside a container.

Docker Compose

  • docker-compose up: Start the services defined in a docker-compose.yml file.
  • docker-compose down: Stop and remove containers, networks, volumes, and images created by docker-compose up.
  • docker-compose build: Build or rebuild services defined in a docker-compose.yml file.
  • docker-compose ps: List containers managed by Docker Compose.
  • docker-compose logs: View logs for services managed by Docker Compose.
  • docker-compose exec <service> <command>: Execute a command in a running service.

Dockerfile Directives

  • FROM: Specifies the base image.
  • WORKDIR: Sets the working directory inside the container.
  • COPY: Copies files from the host to the container.
  • RUN: Executes a command in the container.
  • CMD: Specifies the command to run when the container starts.
  • EXPOSE: Specifies the port on which the container will listen.
  • ENV: Sets environment variables.
  • ENTRYPOINT: Configures the container to run as an executable.

Docker Cleanup Commands

  • docker system prune: Remove unused data (stopped containers, unused networks, dangling images, etc.).
  • docker container prune: Remove all stopped containers.
  • docker image prune: Remove unused images.
  • docker volume prune: Remove all unused volumes.
  • docker network prune: Remove all unused networks.

Miscellaneous

  • docker inspect <container_or_image>: Return low-level information on Docker objects (containers, images, volumes, etc.).
  • docker stats: Display a live stream of container(s) resource usage statistics.
  • docker top <container>: Display the running processes of a container.
  • docker cp <container>:<path> <local_path>: Copy files from a container to the host or vice versa.

Day 1

9 July 2024 at 05:58

For the initial refresh of my Python Programming started with the print statements, format, float/string display, concatenation (with/out space), displaying special character (such as \ (backslash), " (double-quotes))

For all the the programming execution used the online compilers (link: https://www.programiz.com/python-programming/online-compiler/)

My PC also having Python 3.12.x

PS C:\Users\usr> python --version
Python 3.12.3

----- below is some sample experiments and its coding part -----

*How do you print the string β€œHello, world!” to the screen?
*

print("Hello, world!")

*How do you print the value of a variable name which is set to β€œSyed Jafer” or Your name?
*

name="First Second"
print("Name: ", name)

*How do you print the variables name, age, and city with labels β€œName:”, β€œAge:”, and β€œCity:”?
*

name="First Second"
age=25
City="Current Place"
print("Name:", name)
print("Age:", age)
print("City:", City)

*How do you use an f-string to print name, age, and city in the format β€œName: …, Age: …, City: …”?
*

name="First Second"
age=25
City="Current Place"
print(f"Name:", name)
print(f"Age:", age)
print(f"City:", City)

*How do you concatenate and print the strings greeting (β€œHello”) and target (β€œworld”) with a space between them?
*

`greeting="Hello"
target="world"

print(greeting, target)`

*How do you print three lines of text with the strings β€œLine1”, β€œLine2”, and β€œLine3” on separate lines?
*

text1="Line1"
text2="Line2"
text3="Line3"
print(text1+"\n"+text2+"\n"+text3)

*How do you print the string He said, "Hello, world!" including the double quotes?
*

print(f"\"Hello World\"")

*How do you print the string C:\Users\Name without escaping the backslashes?
*

print(f"c:\\Users\\Name")

*How do you print the result of the expression 5 + 3?
*

result=5+3
print(result)

*another way
*

print(5+3)

*How do you print the strings β€œHello” and β€œworld” separated by a hyphen -?
*

print(f"hello"+"-"+"world")

*How do you print the string β€œHello” followed by a space, and then print β€œworld!” on the same line?
*

print(f"Hello", "World!")

*How do you print the value of a boolean variable is_active which is set to True?
*

is_active=True
print(is_active)

*How do you print the string β€œHello ” three times in a row?
*

print(3*"Hello")

*How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?
*

temperature=22.5
print("The temperature is", temperature, "degrees Celsius")

*How do you print name, age, and city using the .format() method in the format β€œName: …, Age: …, City: …”?
*

name="First Second"
age=25
city="Current living"
print("Name: {}, Age: {}, City: {}".format(name, age, city))

*How do you print the value of pi (3.14159) rounded to two decimal places in the format The value of pi is approximately 3.14?
*

pi = 22/7 #3.14159
print("Normal display as float", pi)
print("The value of pi after 2 decimal truncated using format is {:.2f}".format(pi))

*How do you print the words β€œleft” and β€œright” with β€œleft” left-aligned and β€œright” right-aligned within a width of 10 characters each?
*

`left="Left-aligned"
right="Right-Aligned"

print("Left: {:.10s} Right: {:.10s}".format(left, right))`

❌
❌