Help Center/ Cloud Container Instance/ User Guide/ Workload/ Setting Container Startup Commands
Updated on 2023-02-07 GMT+08:00

Setting Container Startup Commands

Starting the container is to start the main process. However, some preparations must be made before the main process is started. For example, you configure or initialize MySQL databases before running MySQL servers. You can set ENTRYPOINT or CMD in the Dockerfile when you create an image. As shown in the following, the ENTRYPOINT ["top", "-b"] command is set in the Dockerfile. This command will be executed during container startup.

FROM ubuntu
ENTRYPOINT ["top", "-b"]

The startup command must be supported by the container image. Otherwise, the container startup will fail.

In CCI, you can also set the container startup command. For example, to add the preceding command in the Dockerfile, you can click Add and enter the top command, and then click Add again and enter -b in the Advanced Settings area when you create a workload, as shown in the following figure.

Figure 1 Startup command

When the container engine runs, only one ENTRYPOINT command is supported. The startup command that you set in CCI will overwrite the ENTRYPOINT and CMD commands that you set in the Dockerfile when you created the image. The following table lists the rules.

Image Entrypoint

Image CMD

Command for Running a Container

Parameter for Running a Container

Command Executed

[touch]

[/root/test]

Not set

Not set

[touch /root/test]

[touch]

[/root/test]

[mkdir]

Not set

[mkdir]

[touch]

[/root/test]

Not set

[/opt/test]

[touch /opt/test]

[touch]

[/root/test]

[mkdir]

[/opt/test]

[mkdir /opt/test]