ubuntu
image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.docker pull
or docker run
commands, the required images are pulled from your configured registry. When you use the docker push
command, your image is pushed to your configured registry.docker run hello-world
command.image name
can be any image from Docker Hub or our local machine. I hope that you've noticed that I've been saying create and run and not just run, the reason behind that is the docker run command actually does the job of two separate docker commands. They are:docker create <image name>
creates a container from given image and returns the container id. docker start <image name>
starts a container by given id of a already created command.c41d97e867380b372f56d4801e9e83b2b528da17792c390b4825bbb2289f9bcf
This id can be used to start the built container.c41d97e867
should be fine. -a
or --attach
option: docker ps
command :-a
or --all
option indicates that we want to see not only the running containers but also the stopped ones. Executing ps without the -a option will list out the running containers only.start
command to run a container. There is another command for starting containers called restart
. Though the commands seem to serve the same purpose on the surface, they have a slight difference.start
command starts containers that are not running. The restart
command, however, kills a running container and starts that again. If we use restart with a stopped container then it'll function just as same as the start command.rm
command. Generic syntax for this command is as follows:docker run ubuntu
command, we'll see nothing happens. But if we execute the command with -it
option as follows:-it
option is that the Ubuntu image is configured to start bash upon startup. Bash is an interactive program – that means if we do not type in any commands, bash won't do anything.-it
option sets the stage for us to interact with any interactive program inside a container. This option is actually two separate options mashed together.-i
option connects us to the input stream of the container, so that we can send inputs to bash. -t
option makes sure that we get some good formatting and a native terminal like experience. To exit use ctrl+c or close the terminal and the container will be stopped.
The list of valid arguments usually depends on the entry-point program itself. If the container uses the shell as entry-point, any valid shell command can be passed as arguments. If the container uses some other program as the entry-point then the arguments valid for that particular program can be passed to the container.
-d
or --detach
option. To run the container in detached mode, execute the following command:You can exit simply by pressing ctrl+p + ctrl+q key combination or closing the terminal window. Keep in mind however, the server will keep running in the background even if you exit out of the CLI program.
exec
command with sh
being the executable like the following command:docker stop <container id>
attempts to stop the container gracefully by sending a SIGTERM signal to the container. If the container doesn't stop within a grace period, a SIGKILL signal is sent. docker kill <container id>
stops the container immediately by sending a SIGKILL signal. A SIGKILL signal can not be ignored by a recipient. bb7fadc33178
execute docker stop bb7fadc33178
command. Using docker kill bb7fadc33178
will terminate the container immediately without giving a chance to clean up.logs
command to retrieve logs from a running container. The generic syntax for the command is as follows:970f1a18714a ,
in order to access the logs from the container:-f
or --follow
option and Any later log will show up instantly in the terminal. We can exit by pressing ctrl+c
key combination or simply closing the window. The container will keep running even if you exit out of the log window.