Step-by-Step Guide: Installing Docker on CentOS 7 and Deploying a .NET Core + Angular2 App
This tutorial walks through updating CentOS 7, adding the Docker repository, installing and testing Docker Engine, creating a Dockerfile for a .NET Core and Angular2 project, building and running the container, configuring Nginx as a reverse proxy, and verifying the deployment in a browser.
Install Docker on CentOS 7
Update the system, add the official Docker repository, install the Docker Engine, enable it to start on boot, and verify the installation.
yum update -y
# Create the repository file
cat > /etc/yum.repos.d/docker.repo <<'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
# Install Docker Engine
yum install -y docker-engine
# Enable and start the service
systemctl enable docker.service
systemctl start docker
# Verify with the hello‑world image
docker run --rm hello-worldPrepare a .NET Core + Angular 2 Application for Docker
Copy the existing project directory to a new folder that will be used as the Docker build context. cp -r acore/* dockerapp/ Create a Dockerfile that uses the exact .NET Core runtime version required by the application (1.0.1) and makes the application listen on all interfaces ( 0.0.0.0) so that it is reachable from outside the container.
FROM microsoft/dotnet:1.0.1-core
RUN mkdir /app/
COPY . /app/
WORKDIR /app
EXPOSE 4000
CMD ["dotnet", "acore.dll", "--server.urls", "http://0.0.0.0:4000"]Build and Run the Docker Image
Build the image with a tag, then start a container mapping the host port 8000 to the container port 4000.
# Build the image (note the trailing dot for the build context)
docker build -t dockerapp:1.0 .
# List images to confirm
docker images
# Run the container
docker run --name dockerapp -d -p 8000:4000 dockerapp:1.0
# Verify the container is running
docker ps -aConfigure Nginx as a Reverse Proxy
Update the Nginx server block to proxy HTTP traffic to http://127.0.0.1:8000 (the host‑side port mapped to the container) and reload the service.
# Example snippet for /etc/nginx/conf.d/dockerapp.conf
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# Reload Nginx
service nginx restartVerification
Open a web browser and navigate to http://<host>:8000 (or the domain configured in Nginx). The .NET Core application should be served through Nginx, confirming that the Docker deployment and reverse‑proxy configuration are successful.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
