Dockerfile

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is Dockerfile?

A Dockerfile is simply a text-based script of instructions that is used to create a container image. Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Create a file from an image

docker pull busybox:latest docker save -o myfile.tar busybox:latest The save command exports an image Using -o I can specify the name of the output file.

Load an image from a file

$ docker load -i myfile.tar

Remove an image from my computer

$ docker rmi <image name>

Container restart policy?

A container restart policy, set with the --restart flag at container-creation time, will help my systems automatically recover in the event of a failure.

How do you do cleanup?

With Docker, the whole cleanup process is reduced to one of a few simple commands. In any cleanup task, I must first identify the container that I want to stop and/or remove.

What are the states of a container?

a Docker container can be in one of six states: Created Running Restarting Paused Removing Exited (also used if the container has never been started)

What is entrypoint?

Docker containers run something called an entrypoint before executing the command. Entrypoints are perfect places to put code that validates the preconditions of a container.

How do you build an image?

I build an image using the docker build command. docker build -t getting-started . -- The -t flag tags my image. Think of this simply as a human-readable name for the final image. Since I named the image getting-started, I can refer to that image when I run a container. The . at the end of the docker build command tells that Docker should look for the Dockerfile in the current directory.

How do you get PID namespace of each process running inside a container?

I can get the list of PID namespaces of the processes by running exec subcommand: docker exec lamp-test ps

How can you see which processes are running inside a container?

I see which processes are running inside a container by using the docker top command: $ docker top lamp-test The top subcommand will show the host PID for each of the processes in the container.

login / logout

Running docker login will prompt you for your Docker.com credentials. Once I've provided them, my command-line client will be authenticated, and I'll be able to access my private repositories. When I've finished working with my account, I can log out with the docker logout command.

$ docker exec

The docker exec command can be used to run additional processes inside a running container.

Remove a container from my computer

To remove a container from myncomputer, I use the docker rm command. For example, to delete the stopped container named wp, I'd run this: docker rm wp If I try to remove a container that's running, paused, or restarting, Docker will display a message like the following: Error response from daemon: Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f The processes running in a container should be stopped before the files in the container are removed. I can do this with the docker stop command or by using the -f flag on docker rm. -- The key difference is that when I stop a process by using the -f flag, Docker sends a SIG_KILL signal, which immediately terminates the receiving process. -- In contrast, using docker stop will send a SIG_HUP signal. Recipients of SIG_HUP have time to perform finalization and cleanup tasks. -- The SIG_KILL signal makes for no such allowances and can result in file corruption or poor network experiences. -- I can issue a SIG_KILL directly to a container by using the docker kill command. But I should use docker kill or docker rm -f only if you must stop the container in less than the standard 30-second maximum stop time. if I'm experimenting with short-lived containers, you can avoid the cleanup burden by specifying --rm on the command. Doing so will automatically remove the container as soon as it enters the exited state. For example, the following command will write a message to the screen in a new BusyBox container, and the container will be removed as soon as it exits: docker run --rm --name auto-exit-test busybox:1.29 echo Hello World docker ps -a docker rm -vf $(docker ps -a -q)

How can you kill a process inside a container from within that container?

to kill a process inside a container from within that container, I need to know the PID in the container's PID namespace. To get that list, run the following exec subcommand: docker exec lamp-test ps Then run docker exec lamp-test kill <PID> Running this command will run the Linux kill program inside the lamp-test container and tell the apache2 process to shut down.

How do you list all the running containers on your computer?

to list all the containers on my computer, use the docker ps command without -a flag: docker ps

How do list all the containers on your computer?

to list all the containers on my computer, use the docker ps command: docker ps -a


Kaugnay na mga set ng pag-aaral

Chapter 21 Cardiovascular System: Blood Vessels and Circulation

View Set

Law 332- Unit 2-B Review Exercise (Chapter 31)

View Set

Chapter 7: Causes of the American Revolution

View Set