1
00:00:00,000 --> 00:00:11,560
In this video, you'll learn how to run containers in either Docker or Popman.

2
00:00:11,560 --> 00:00:17,000
So the Popman command on Red Hat is fully compatible with the Docker command.

3
00:00:17,000 --> 00:00:21,320
And if you're on Red Hat and you want to follow along exactly with the Docker command, there's

4
00:00:21,320 --> 00:00:22,559
an easy solution.

5
00:00:22,559 --> 00:00:25,480
Use export alias Docker is Popman.

6
00:00:25,480 --> 00:00:29,980
And unless you are a very advanced user, you won't notice any difference.

7
00:00:29,980 --> 00:00:35,939
To run a container, the basic idea is the command docker run image, where image refers

8
00:00:35,939 --> 00:00:41,700
to the name of the specific container image that was found on Docker Hub.

9
00:00:41,700 --> 00:00:45,740
Docker Hub is a standard container registry that Docker is using.

10
00:00:45,740 --> 00:00:48,099
Check it out on hub.docker.com.

11
00:00:48,099 --> 00:00:52,340
It has a website that allows you to search for container images.

12
00:00:52,340 --> 00:00:57,259
The run command is commonly used with options minus D, which runs the container in detached

13
00:00:57,259 --> 00:00:58,619
mode.

14
00:00:58,619 --> 00:01:03,560
Dot minus D is going to occupy your screen and you don't see anything else.

15
00:01:03,560 --> 00:01:08,019
Minus IT is commonly used to run a container in interactive terminal mode.

16
00:01:08,019 --> 00:01:13,260
That is what you want to do if you want to run a shell on the container you just started.

17
00:01:13,260 --> 00:01:18,459
And to get an overview of all containers that you just started, you use Docker PS, optionally

18
00:01:18,459 --> 00:01:22,820
with the minus A option, which will also show you containers that have been started in the

19
00:01:22,820 --> 00:01:25,540
past and which are now no longer running.

20
00:01:25,540 --> 00:01:27,540
Let me show you.

21
00:01:27,540 --> 00:01:31,220
So we have already done a docker run minus D nginx.

22
00:01:31,220 --> 00:01:37,459
And if at this point I'm using Docker PS, then I can see my currently running container.

23
00:01:37,459 --> 00:01:41,019
The container has an ID, which I can use for managing.

24
00:01:41,019 --> 00:01:45,459
It uses a standard command, which is normally a script with the name docker entry point,

25
00:01:45,459 --> 00:01:49,019
which is going to take care of what exactly you want to do.

26
00:01:49,019 --> 00:01:53,779
It's exposing its services on the port, and it has an automatically generated name that

27
00:01:53,779 --> 00:01:56,500
you might want to use for managing.

28
00:01:56,500 --> 00:02:02,699
If I would use docker run minus IT BusyBox, there we have another example.

29
00:02:02,699 --> 00:02:07,620
I'm using the BusyBox container image, which is a commonly used container image.

30
00:02:07,620 --> 00:02:09,899
It's commonly used because it's so small.

31
00:02:09,899 --> 00:02:14,979
It's a minimal Linux distribution that fits in just a couple of megabytes.

32
00:02:14,979 --> 00:02:19,380
Now here you can see that suddenly I'm in a root shell, and that is because I'm within

33
00:02:19,380 --> 00:02:21,899
the BusyBox container image.

34
00:02:21,899 --> 00:02:29,860
I would advise if you're ever wondering where you are, check out the OS release file.

35
00:02:29,860 --> 00:02:33,940
And oh boy, BusyBox is so small, it doesn't even have an OS release.

36
00:02:33,940 --> 00:02:37,699
OS release is the file that's the Linux Foundation standard.

37
00:02:37,699 --> 00:02:44,460
It should be there on all Linux distributions to identify the distribution where you are.

38
00:02:44,460 --> 00:02:47,619
Now here I'm in the shell that was started by BusyBox.

39
00:02:47,619 --> 00:02:51,020
If I'm going to use exit, I'm exiting that shell.

40
00:02:51,139 --> 00:02:55,619
But then when I'm using docker ps, I don't see BusyBox anymore.

41
00:02:55,619 --> 00:03:00,820
That's because the shell was the primary command, and if you exit the container primary command,

42
00:03:00,820 --> 00:03:01,940
it's gone.

43
00:03:01,940 --> 00:03:08,179
So now I need docker ps minus a, and docker ps minus a is showing all of them, including

44
00:03:08,179 --> 00:03:11,380
containers that were exited.

45
00:03:11,380 --> 00:03:14,220
Now when containers are running, you can manage them.

46
00:03:14,220 --> 00:03:17,779
In order to do so, there's a couple of commands involved.

47
00:03:17,779 --> 00:03:22,899
Starting with docker inspect, which shows properties of your containers.

48
00:03:22,899 --> 00:03:25,860
Docker stop will stop a running container.

49
00:03:25,860 --> 00:03:32,139
And docker exec minus t, container name slash bin slash bash, opens a shell in a currently

50
00:03:32,139 --> 00:03:33,699
running container.

51
00:03:33,699 --> 00:03:35,660
And that is useful for debugging.

52
00:03:35,660 --> 00:03:37,059
Let me show you.

53
00:03:37,059 --> 00:03:43,020
So I want to inspect my quirky query, which is the nginx container.

54
00:03:43,020 --> 00:03:48,419
Docker inspect qutab will do it for me.

55
00:03:48,419 --> 00:03:55,339
And here we can see in JSON format everything that is going on in the container.

56
00:03:55,339 --> 00:04:00,899
An important part is the path, path is the default application, which was started with

57
00:04:00,899 --> 00:04:01,899
these arguments.

58
00:04:01,899 --> 00:04:05,039
And here you can see that it has started nginx.

59
00:04:05,039 --> 00:04:09,699
And if you scroll further down, you can find all the properties of the container.

60
00:04:09,699 --> 00:04:15,139
And that is really useful if your container isn't doing what you want it to do.

61
00:04:15,139 --> 00:04:19,540
Now this quirky query container is running in the background.

62
00:04:19,540 --> 00:04:25,339
And I can connect to it using docker exec minus it for the interactive terminal on a

63
00:04:25,339 --> 00:04:27,339
quirky query.

64
00:04:27,339 --> 00:04:31,500
And I'm going to run slash bin slash bash.

65
00:04:31,500 --> 00:04:36,579
Now one thing you should notice, not all containers have bin bash on board, because containers

66
00:04:36,579 --> 00:04:39,579
are often used as minimal environments.

67
00:04:39,579 --> 00:04:45,660
And if it's giving an error message on bin bash, I would advise you use bin sh instead.

68
00:04:45,660 --> 00:04:50,859
So now I'm inside the container, and I can check, for instance, which processes are running.

69
00:04:50,859 --> 00:04:57,260
Well, that doesn't work exactly for the simple reason that, as you can see here, the ps command

70
00:04:57,260 --> 00:04:59,019
is not found.

71
00:04:59,019 --> 00:05:01,220
That's the nature of containers.

72
00:05:01,220 --> 00:05:03,260
Containers are minimal environments.

73
00:05:03,260 --> 00:05:09,579
They are images that contain what you need to run your application and nothing else.

74
00:05:09,579 --> 00:05:13,820
So in this case, ps command not found, well, that's not going to work.

75
00:05:13,820 --> 00:05:17,500
But I can use ls to see files in this container.

76
00:05:17,500 --> 00:05:21,100
When I use exit, don't worry, you don't shut the container down.

77
00:05:21,100 --> 00:05:23,940
Look, docker ps is still showing it.

78
00:05:23,940 --> 00:05:29,100
I used exit on the docker exec shell that I just started.

79
00:05:29,100 --> 00:05:31,579
And this docker exec shell was a secondary command.

80
00:05:31,859 --> 00:05:37,019
This doesn't show, so it doesn't shut down the entire container.

81
00:05:37,019 --> 00:05:41,899
If you want to shut down a container, use docker stop on your container.

82
00:05:41,899 --> 00:05:43,700
And now it will go away.

83
00:05:43,700 --> 00:05:45,500
Let's check that.

84
00:05:45,500 --> 00:05:48,100
Docker ps doesn't show it anymore.

85
00:05:48,100 --> 00:05:50,179
And that's exactly what I wanted.

86
00:05:50,179 --> 00:05:54,140
We also need to talk about accessing container workloads.

87
00:05:54,140 --> 00:05:59,299
The entry point application, that's a standard application that your container is starting.

88
00:05:59,299 --> 00:06:04,220
And that can expose a port, but this port by default is not accessible from the outside,

89
00:06:04,220 --> 00:06:08,739
because network-wise, containers run in an isolated environment.

90
00:06:08,739 --> 00:06:14,100
Only root containers will have an IP address on the isolated container network.

91
00:06:14,100 --> 00:06:21,940
To access a container, you need port forwarding to expose the container port on the host where it is running.

92
00:06:21,940 --> 00:06:27,619
You do that using a command like docker run minus p 8080 colon 80 nginx,

93
00:06:27,619 --> 00:06:34,940
which will run the container based on an nginx image and expose the container port on port 8080.

94
00:06:34,940 --> 00:06:39,059
You cannot expose ports on containers that have already been started.

95
00:06:39,059 --> 00:06:40,339
Let me show you.

96
00:06:40,339 --> 00:06:46,660
So I'm going to use docker run minus p 8080 colon 80 nginx.

97
00:06:46,660 --> 00:06:51,779
Of course, the first port number, that's where you expose your port, needs to be available.

98
00:06:51,779 --> 00:06:54,980
And oops, let me also use minus d.

99
00:06:54,980 --> 00:07:01,859
Notice that the arguments for docker run should always be behind docker run and not behind the container name.

100
00:07:01,859 --> 00:07:05,459
Because if you put the argument behind the name of the container image,

101
00:07:05,459 --> 00:07:12,019
it's going to be interpreted as an argument for the primary command that your container image is going to run.

102
00:07:12,019 --> 00:07:20,059
Good. Now when I use docker ps, I can see that it has 0000 8080 forwarding to port 80,

103
00:07:20,059 --> 00:07:27,260
meaning that if I would use curl to localhost 8080, I'm getting access.

104
00:07:27,260 --> 00:07:29,500
Oh, no curl? Let's fix that.

105
00:07:29,500 --> 00:07:32,820
sudo apt install curl.

106
00:07:32,820 --> 00:07:34,660
And now I'm going to try it again.

107
00:07:34,660 --> 00:07:38,059
curl localhost, and there we can see welcome to nginx.

108
00:07:38,059 --> 00:07:42,299
It doesn't give anything cool, but it does prove that the container is accessible.

