Implementation of static website layout in docker container

Implementation of static website layout in docker container

Server placement

It is recommended to use cloud servers (Alibaba Cloud, Huawei Cloud, Tencent Cloud) which can be used for free for a few days. After we buy a server, we will encounter the following problems:

The local computer pings the server host and finds that the ping fails and the request times out.

We need to find the security group column in the management server interface, and then add icmp when entering and exiting the security group. It is recommended to add all with one click.


Then we can ping the server from the local computer.

Docker installation

After setting up the cloud server, we use apt-get update, apt-get upgrade to update information.



Then, we enter docker and the following error occurs:


Next, we follow the usual software method apt-get install docker.io, apt-get install docker.ce , and find the following problems

Package 'docker-ce' has no installation candidate

The solution is as follows:

#Add docker source sudo echo "deb https://download.docker.com/linux/ubuntu zesty edge" > /etc/apt/sources.list.d/docker.list

#Support parsing https
apt-get install -y apt-transport-https ca-certificates curl software-properties-common

#Add GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#Set the repository location add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Then we execute it again and get the following result


Next, verify the installation result by typing docker run hello-world

nginx installation

The next step is apt-get install nginx install nginx


The next step is to check the installation effect. Enter the command service start nginx , then enter the server's external network IP address in the browser to see the nginx default interface. There are a few problems here:

1.

Problem: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

Solution: netstat -ntlp | grep 80 to check


Then enter service nginx stop and check again and it is gone.

Problem: nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:86

Solution

vim /etc/nginx/nginx.conf
Add the server {
....
}
Put it in http
...
}
It can be solved

First: mkdir -p /var/www/html
Then cd to the directory and execute vim index.html
Define the content in html yourself, save and exit, and then modify the default index.html path in the configuration file as follows


Then restart nginx, service nginx restart

Browser Testing

Finally, we can start the image of the docker container as follows


Finally, just check the effect. Just enter the address and port number in the browser.

This is the end of this article about the implementation of deploying static websites in docker containers. For more relevant content about deploying static websites in docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Using Docker to create static website applications (multiple ways)

<<:  jQuery implements form validation function

>>:  Steps to install MySQL 8.0.23 under Centos7 (beginner level)

Recommend

MySQL 5.7 deployment and remote access configuration under Linux

Preface: Recently I am going to team up with my p...

How to use watch listeners in Vue2 and Vue3

watch : listen for data changes (change events of...

How to import SQL files in Navicat Premium

I started working on my final project today, but ...

How to modify the default storage location of Docker images (solution)

Due to the initial partitioning of the system, th...

Detailed explanation of the solution to docker-compose being too slow

There is only one solution, that is to change the...

js to achieve drag and drop sorting details

Table of contents 1. Introduction 2. Implementati...

Detailed explanation of Vuex overall case

Table of contents 1. Introduction 2. Advantages 3...

How to use js to determine whether a file is utf-8 encoded

Conventional solution Use FileReader to read the ...

Detailed tutorial on installing and using Kong API Gateway with Docker

1 Introduction Kong is not a simple product. The ...

Detailed tutorial on installing Mysql5.7.19 on Centos7 under Linux

1. Download MySQL URL: https://dev.mysql.com/down...

Detailed explanation of daily_routine example code in Linux

First look at the example code: #/bin/bash cal da...

Solve the problem that the docker container cannot ping the external network

Today, when I was building a redis environment in...

The use of setState in React and the use of synchronous and asynchronous

In react, if you modify the state directly using ...