I opened a public network at home, found several aliyun DDNS tools in DockerHub, tried, does not conform to their own use environment, so I decided to build a mirror of the project files have been on Github, Docker-compos. Yml, DDNS configuration files are available in the following repository: Github github.com/youdmeng/al… DockerHub hub.docker.com/repository/…

Why docker

Docker this thing, it is not too easy to use, especially with docker-compose, a configuration file, different environments, a command is deployed, go to where the use of which, it is not too comfortable.

If you haven’t tried Docker yet, you’re advised to do so.

Build aliyun DDNS service Docker image

In order to build docker image, the smaller the image is, the better under the premise of ensuring the function

So I went with Alpine, an underlying image with just 5MB

Use Dockerfile to build the image

A Dockerfile is a text file used to build an image. The text content contains the instructions and instructions required to build the image

Dockerfile common directives

attribute usage describe
FROM FROM <image>:<tag> Specifies the base image to use
RUN RUN < command line command >/RUN [” executable file “, “parameter 1″,” parameter 2″] Execute specified instructions
COPY COPY < source path > < destination path > Copy the file
ADD ADD < source path > < destination path > More advanced copy files (downloadable URL)
CMD CMD [“executable”,”param1″,”param2″] / CMD [“param1″,”param2”] / CMD command param1 param2 The RUN build runs the command, and the CMD container executes it
ENTRYPOINT ENTRYPOINT [“executable”, “param1”, “param2”] / ENTRYPOINT command param1 param2 Configure an executable program for the container
ENV ENV <key> <value> Setting environment Variables
ARG ARG <name>[=<default value>] Used to specify variables passed to the build run time
VOLUME VOLUME [“/data”] Used to create mount points
EXPOSE EXPOSE <port> [<port>] Set the listening port for the built image
WORKDIR WORKDIR /opt Set the working paths of the RUN, CMD, ENTRYPOINT, ADD, and COPY commands
USER USER daemon Specifies the user used to run the image

Use Dockerfile to build aliyun DDNS image

I made the image based on the GIthub big guy’s DDNS script. Script address: github.com/risfeng/ali…

Ali Cloud DDNS image Dockerfile

Here is the entire DockerFile. I will explain how it works line by line and what it does

FROM docker.io/alpine

RUN echo "#aliyun" > /etc/apk/repositories
RUN echo "https://mirrors.aliyun.com/alpine/v3.6/main/" >> /etc/apk/repositories
RUN echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN apk add curl
RUN apk add openssl
RUN apk add util-linux
RUN apk add --update --no-cache bind-tools
RUN curl -O https://raw.githubusercontent.com/risfeng/aliyun-ddns-shell/master/src/aliyun/aliyun-ddns.sh
RUN chmod 777 ./aliyun-ddns.sh
RUN mv /aliyun-ddns.sh /opt/aliyun-ddns.sh
RUN sed -i 's#LOG_FILE_PATH=""#LOG_FILE_PATH="/etc/logs/ddns.log"#g' /opt/aliyun-ddns.sh
RUN echo "*/15 * * * * /opt/aliyun-ddns.sh -run" >> /var/spool/cron/crontabs/root 
Copy the code
Introduce an official base image

FROM docker.io/alpine

Alpine is introduced because we use the official base image

How do I know which commands I can execute in Alpine?

Try it yourself, of course, by running Alpine

Run: docker run it docker. IO /alpine /bin/ash

Step by step on the command line to configure your own service, each step you do, is a command in the Dockerfile

Explain, line by line, how each line of code works and what it does

RUN the echo “# aliyun” > / etc/apk/repositories RUN echo “mirrors.aliyun.com/alpine/v3.6…” > > / etc/apk/repositories RUN echo “mirrors.aliyun.com/alpine/v3.6…” >> /etc/apk/repositories

Here is to configure APT source in Alpine mirror as Ali source to improve the download speed of domestic components

The RUN command is used to execute the specified command, using shell mode (RUN < command line command >), which is equivalent to running alpine, echo “#aliyun” on the command line.

Use the echo command to modify the file contents

The Shell echo directive is similar to the PHP echo directive in that it is used to output strings

  • Echo String prints string directly to the console
  • Echo “$name” reads the value of the variable name
  • Echo “#aliyun” > /etc/apk/repositories
  • echo dateExecute a command and print the result to the console

RUN apk update

RUN apk upgrade

Here’s an update to Alpine

RUN apk add bash

RUN apk add curl

RUN apk add openssl

RUN apk add util-linux

RUN apk add –update –no-cache bind-tools

Here is the environment on which the DDNS script installation depends

The RUN curl – raw.githubusercontent.com/risfeng/ali O… RUN chmod 777 ./aliyun-ddns.sh RUN mv /aliyun-ddns.sh /opt/aliyun-ddns.sh

Download the DDNS script, move it, and empower it

Use the sed command to replace the specified file characters

The Linux sed command uses scripts to process text files.

RUN sed -i ‘s#LOG_FILE_PATH=””#LOG_FILE_PATH=”/etc/logs/ddns.log”#g’ /opt/aliyun-ddns.sh

This is to change the log path of the script we downloaded

Sed command description:

  • A: New, a can be followed by a string, which will appear on a new line (the current next line) ~
  • C: replace, c can be followed by a string, these string can replace n1,n2 line!
  • D: Delete. D: Delete.
  • I: insert, I can be followed by a string, which will appear on a new line (currently the previous line);
  • P: Print, or print out selected data. Normally p is run with the sed-n argument ~
  • S: Replace, can directly replace the work! Usually the action of this S can be paired with the formal notation! 1,20s/old/new/g

/opt/ aliyun-danns. sh insert LOG_FILE_PATH=”/etc/logs/ danns.log “, s instead of LOG_FILE_PATH=””

/opt/aliyun-ddns.sh replace LOG_FILE_PATH=”” with LOG_FILE_PATH=”” in /opt/aliyun-ddns.sh

The last step

RUN echo “*/15 * * * * /opt/aliyun-ddns.sh -run” >> /var/spool/cron/crontabs/root

In the same way, modify Alpine’s timer configuration file to run /opt/aliyun-ddns.sh -run every 15 minutes

Run component commands

Docker build -t DDNS: 1.0

Of course, using vscode to operate docker is also very convenient, you can try.

You’re done

Use Docker run command to start the image, or use docker-compose to compose start, you will have their own Aliyun DDNS Docker service

The project files for this article have been published on Github and DockerHub

The usage of this image as well as the Docker-compos. Yml and DDNS configuration files are provided in the following repository

Github Github.com/youdmeng/al…

DockerHub Hub.docker.com/repository/…

Welcome to STAR

For more interesting and interesting content, welcome to my blog to communicate and improve WaterMin together