Install an Apache server (based on Ubuntu) in Docker and access this server on an external computer
In the previous blog, we discussed how to install a Docker app in Ubuntu 14.04 (64-bit), and the usage of some basic Docker commands and their explanations:
http://blog.csdn.net/error/404.html?from=http%3a%2f%2fblog.csdn.net%2fliujan511536%2farticle%2fdetails%2f46227169
Next we say how to use Docker to build an Apache server image and upload our HTML file to this image, and finally we can access the Apache server in this Docker from a computer outside Dcoker.
I'm using XAMPP to set up a server here.
Note: If you don't understand some of the following commands, check out my previous blog post.
First download XAMPP, choose Linux version:
: https://www.apachefriends.org/download.html
To start Docker:
Service Docker start
Or use this command:
sudo docker-d
(If you have any questions about startup, see the FAQ at the end of the blog)
Then upload our downloaded xampp.run to the container, where my xampp.run is placed in the/home/download directory, assuming my image is called Ubuntu
sudo docker run–i–t–v/home/download/xampp.run:/tmp/xampp.run ubuntu /bin/bash
After running the above command, a container is launched and entered into the container command line;
Then install XAMPP
(xampp default installation path in Ubuntu is/OPT/LAMPP)
Enter the TMP directory in the container:
Cd/tmp
Run Xampp.run (here if there are any permissions issues, use sudo chmod 777 * to resolve):
sudo./xampp.run
Then is the installation process, there is a need to enter the place, for convenience can be directly press Enter or Y can be.
After installing XAMPP, enter:
Mysql–u Root
The display is command not found, because we have not yet added the MySQL executable directory to the environment variable path.
Add the MySQL executable file directory (the default directory is/opt/lamp/bin) to the path:
sudo vim ~/.bashrc #没有vim可用sudo apt-get install vim installation vim
After opening the. BASHRC, add this sentence at the end:
Export path= $PATH:/opt/lampp/bin
After saving, exit vim, then enter the command to make the above changes effective:
SOURCE ~/.BASHRC
The following commands can be used to start Apache,mysql and PHP:
/opt/lampp/lampp Start
The MySQL interpreter can then enter MySQL (enter exit to exit the interpreter)
Then open another command line terminal in the local computer, enter:
sudo docker PS
To see the ID of the container that was just running, then exit the container (enter exit on the container command line), and then save that container as a new image:
sudo docker commit container ID New image name
Then start the newly saved image, assuming the image is named UBUNTU2:
sudo docker run–i -t–p 8088:80 Ubuntu2/bin/bash
Start Apache and MySQL by entering the following command on the Boot container command line:
/opt/lampp/lampp Start
Here, you can access the Apache server in the above container on your native computer.
Open your computer's browser and enter it in the Address bar:
localhost:8088
And then the page that appears is XAMPP's page.
(if the page shown here is not connected, please turn off the container and restart the container)
Go back to the command line for that container and go to the directory where the HTML file is stored in Apache (default is/opt/lampp/htdocs):
Cd/opt/lampp/htdocs
Then create a new HTML file under the Htdcos directory:
sudo vim hello.html
The contents of the file are:
HelloWorld
Save and exit Vim.
Then, in the local Computer browser address bar, enter:
Localhost:8088/hello.html
No accident, you can see HelloWorld, if there is an accident, such as show access forbidden, please go back to the container command line, go to htdocs directory, modify hello.html permissions (sudo chmod 777 hello.html).
Here, you've learned how to use Docker to build an Apache server and access the Web pages in the container from an external computer.
Installing the Apache image on the Docer