Docker commands

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How to override ENTRYPOINT command defined in Dockerfile?

docker run --entrypoint [my_entrypoint] test

How to create VOLUME using command line?

docker run -v my_volume:/path/in/docker <image>

What is docker container?

A container is a runtime instance of an image - what the image becomes in memory when executed (that is, an image with state, or a user process)

Why it is necessary to combine apt-get update and apt-get install in the same RUN command?

Using apt-get update alone in a RUN statement causes caching issues and subsequent apt-get install instructions fail.

How to create VOLUME in Dockerfile?

VOLUME ./frontend/src /app/src

How to set the working directory for the container?

WORKDIR /path/to/dir

What is writable (container) layer?

When you run an image and generate a container, you add a new writable layer (the "container layer") on top of the underlying layers. All changes made to the running container, such as writing new files, modifying existing files, and deleting files, are written to this thin writable container layer

How to set ports exposed by the container?

EXPOSE 80/tcp

How to override CMD command defined in Dockerfile?

Everything that follows after the docker run <image> command overrides default CMD command

What does CMD instruction do?

Provides default command for an executing container.

What command should be run at the beginning of the RUN instruction when installing packages?

> apt-get update

How to check docker version?

> docker -v

How to build an image with a custom tag?

> docker build -t <image_name>:<tag_name> ./path/to/Dockerfile

How to build an image?

> docker build ./path/to/Dockerfile

How to create a new container?

> docker create <image>

How to enter to the running container?

> docker exec -it <container> bash

How to list all images?

> docker image ls / docker images

How to remove an image?

> docker image rm <image> / docker rmi <image>

How to view details about docker installation?

> docker info

How to force shutdown a container?

> docker kill <name|id>

How to login to the docker hub account?

> docker login

How to list running containers?

> docker ps

How to list all containers?

> docker ps -a

How to restart a container?

> docker restart <name|id>

How to remove all containers?

> docker rm $(docker container ls -a -q)

How to remove a container?

> docker rm <name|id>

How to remove all images?

> docker rmi $(docker images -q)

How to pass environment variables to the new container?

> docker run --env KEY=VALUE <image>

How to run a container in the background

> docker run -d <image>

How to run a container in the interactive session?

> docker run -it <image>

How to run a container?

> docker run <image>

How to set a name for a new container?

> docker run <image> --name NAME

How to map external port to the docker port?

> docker run <image> -p EXT:INT

How to start a container?

> docker start <name|id>

How to gracefully stop a container?

> docker stop <name|id>

How to remove unused images?

> docker system prune

What command should be run at the end of the RUN instruction when installing packages?

> rm -rf /var/lib/apt/lists/* This command removes caches, thus reducing image size

How to copy remote files to the container?

ADD url relativeDir/ || ADD url /absoluteDir/

How to exclude files and directories from copying to the docker?

Add them to the .dockerignore file

What does LABEL instruction do?

Adds metadata to an image.

What does ONBUILD command do?

Adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build

What does ENTRYPOINT instruction do?

Allows you to configure a container that will run as an executable. The entrypoint command will be run when container starts

What is a docker image?

An image is an executable package that includes everything needed to run an application - the code, a runtime, libraries, environment variables, and configuration files.

Why it is not good to call apt-get upgrade and dist-upgrade inside the container?

Because many of the "essential" packages from the parent images cannot upgrade inside an unprivileged container. Use "apt-get install -y foo" instead to update "foo" package

How to set the default executable command which will be called when container starts?

CMD ["executable","param1","param2"]

How to copy local files to the container?

COPY test relativeDir/ || COPY test /absoluteDir/

What does COPY instruction do?

Copies new files, directories from <src> and adds them to the filesystem of the image at the path <dest>.

What does ADD instruction do?

Copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>.

What does VOLUME command do?

Creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers

What is the gotcha when using pipes?

Docker executes these commands using the /bin/sh -c interpreter, which only evaluates the exit code of the last operation in the pipe to determine success even if previous commands failed. Put this command right after beginning of the RUN instruction: "set -o pipefail"

How to set environment variables?

ENV myName="John Doe" myDog=Rex

How to set the base image for container?

FROM <image>[:<tag>]

What does EXPOSE instruction do?

Functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.

What if WORKDIR is a relative path?

If a relative path is provided, it will be relative to the path of the previous WORKDIR instruction

When it is preferred to use ENTRYPOINT instruction?

If you don't want the developers to override the default executable command (although it can be overridden by the --entrypoint flag)

What is the gotcha when using ENV instruction?

If you unset the environment variable in a future layer, it will be unset only in that layer and persists across all future layers. To really unset env variable - set and unset it in the same layer.

When it is preferred to use CMD instruction?

If you want to let the developer override default executable command

What does FROM instruction do?

Initializes a new build stage and sets the Base Image for subsequent instructions.

How to add metadata to the image?

LABEL version="1.0"

What does ENV instruction do?

Sets the environment variable <key> to the value <value>

What does USER instruction do?

Sets the user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions

What does WORKDIR instruction do?

Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile

What is the difference between 'shell' and 'exec' mode?

Shell mode provides env variables and has PID = 1

What is a disadvantage when using 'exec' form?

There are no environment variables

How to set user when running a container?

USER <user>[:<group>] || USER <UID>[:<GID>]

What is the difference between ADD and COPY instructions?

Unlike ADD, COPY neither extracts data from archive during copying nor downloads it from remote resources?


संबंधित स्टडी सेट्स

Government in America Chapters 4 & 5: Civil Rights & Liberties

View Set

Stockholders' Equity Learn Smart

View Set

HG&D chapter 3 likely test questions

View Set

Business 101 Test 2 Ch. 8,11,12,13

View Set

Four Essential Features of A State

View Set