docker:run_apache_server
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
docker:run_apache_server [2016/10/17 15:10] – [Another approach] peter | docker:run_apache_server [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 14: | Line 14: | ||
<code bash> | <code bash> | ||
- | apt-get update && apt-get install apache2 | + | apt update && apt install apache2 |
</ | </ | ||
You’re probably wondering what address you can connect to in order to test that Apache was correctly installed…we’ll get to that after we commit the container. | You’re probably wondering what address you can connect to in order to test that Apache was correctly installed…we’ll get to that after we commit the container. | ||
- | **NOTE**: | + | <WRAP info> |
+ | **NOTE**: | ||
+ | If the image doesn’t exist on your local machine, Docker will attempt to fetch it from the public image registry | ||
+ | </ | ||
+ | |||
+ | ---- | ||
===== Committing a container ===== | ===== Committing a container ===== | ||
Line 40: | Line 45: | ||
The overlay filesystem works similar to git: our image now builds off of the **ubuntu** base and adds another layer with Apache on top. These layers get cached separately so that you won’t have to pull down the ubuntu base more than once. | The overlay filesystem works similar to git: our image now builds off of the **ubuntu** base and adds another layer with Apache on top. These layers get cached separately so that you won’t have to pull down the ubuntu base more than once. | ||
+ | ---- | ||
===== Keeping the Apache container running ===== | ===== Keeping the Apache container running ===== | ||
- | Now we have our Ubuntu container with Apache running in one shell and an image of that container sitting on disk. Let’s launch a new container based on that image but set it up to keep running indefinitely. | + | Now we have our Ubuntu container with Apache running in one shell and an image of that container sitting on disk. |
+ | |||
+ | Let’s launch a new container based on that image but set it up to keep running indefinitely. | ||
+ | |||
+ | The basic syntax looks like this, but we need to configure a few additional options that we’ll fill in as we go: | ||
<code bash> | <code bash> | ||
Line 55: | Line 65: | ||
</ | </ | ||
+ | ---- | ||
===== Run container detached ===== | ===== Run container detached ===== | ||
- | When running Docker containers manually, the most important option is to run the container in detached mode with the **-d** flag. This will output the container ID to show that the command was successful, but nothing else. At any time you can run docker ps in the other shell to view a list of the running containers. Our command now looks like: | + | When running Docker containers manually, the most important option is to run the container in detached mode with the **-d** flag. |
+ | |||
+ | This will output the container ID to show that the command was successful, but nothing else. | ||
+ | |||
+ | At any time you can run docker ps in the other shell to view a list of the running containers. | ||
+ | |||
+ | Our command now looks like: | ||
<code bash> | <code bash> | ||
Line 68: | Line 85: | ||
Do not run containers with detached mode inside of systemd unit files. | Do not run containers with detached mode inside of systemd unit files. | ||
+ | ---- | ||
===== Run Apache in foreground ===== | ===== Run Apache in foreground ===== | ||
- | We need to run the apache process in the foreground, since our container will stop when the process specified in the **docker run** command stops. | + | We need to run the apache process in the foreground, since our container will stop when the process specified in the **docker run** command stops. |
+ | |||
+ | We can do this with a flag **-D** when starting the apache2 process: | ||
<code bash> | <code bash> | ||
Line 83: | Line 103: | ||
</ | </ | ||
+ | ---- | ||
===== Permanently running a container ===== | ===== Permanently running a container ===== | ||
Line 89: | Line 110: | ||
Instead, create a systemd unit file to make systemd keep that container running. See the [[https:// | Instead, create a systemd unit file to make systemd keep that container running. See the [[https:// | ||
+ | |||
+ | ---- | ||
===== Network access to 80 ===== | ===== Network access to 80 ===== | ||
- | The default apache install will be running on port 80. To give our container access to traffic over port 80, we use the -p flag and specify the port on the host that maps to the port inside the container. | + | The default apache install will be running on port 80. |
+ | |||
+ | To give our container access to traffic over port 80, we use the -p flag and specify the port on the host that maps to the port inside the container. | ||
+ | |||
+ | In our case we want 80 for each, so we include **-p 80:80** in our command: | ||
<code bash> | <code bash> | ||
Line 98: | Line 125: | ||
</ | </ | ||
- | You can now run this command on your CoreOS | + | You can now run this command on your host to create the container. |
+ | You should see the default apache webpage when you load either **localhost: | ||
+ | Be sure that any firewall or EC2 Security Group allows traffic to port 80. | ||
+ | |||
+ | ---- | ||
===== Using the Docker registry ===== | ===== Using the Docker registry ===== | ||
- | Earlier we downloaded the ubuntu image remotely from the Docker public registry because it didn’t exist on our local machine. | + | Earlier we downloaded the ubuntu image remotely from the Docker public registry because it didn’t exist on our local machine. |
+ | |||
+ | We can also push local images to the public registry (or a private registry) very easily with the push command: | ||
<code bash> | <code bash> | ||
Line 110: | Line 143: | ||
</ | </ | ||
- | To push to a private repository the syntax is very similar. | + | To push to a private repository the syntax is very similar. |
+ | |||
+ | First, we must prefix our image with the host running our private registry instead of our username. | ||
+ | |||
+ | List images by running **docker images** and insert the correct ID into the tag command: | ||
<code bash> | <code bash> | ||
Line 129: | Line 166: | ||
- | .................................................. | + | ---- |
===== Another approach ===== | ===== Another approach ===== | ||
Line 167: | Line 204: | ||
- | .................................................. | + | ---- |
===== Office Apache Image ===== | ===== Office Apache Image ===== | ||
Line 260: | Line 297: | ||
CMD [" | CMD [" | ||
</ | </ | ||
+ | |||
+ | ---- | ||
===== Example ===== | ===== Example ===== | ||
Line 277: | Line 316: | ||
Files are accessible on port 80. | Files are accessible on port 80. | ||
+ | ---- | ||
===== References ===== | ===== References ===== | ||
Line 283: | Line 323: | ||
http:// | http:// | ||
+ | |||
+ | |||
+ | TODO check this next link | ||
+ | https:// | ||
+ |
docker/run_apache_server.1476717021.txt.gz · Last modified: 2020/07/15 09:30 (external edit)