刚启动容器时,如何运行Echo Hello World

发布于 2025-01-27 11:52:07 字数 1758 浏览 3 评论 0原文

我有一个如下:

FROM kong
USER 0

RUN mkdir -p /kong/declarative/
COPY declarative/kong.yml /kong/declarative/

# COPY docker-entrypoint.sh /docker-entrypoint.sh
# RUN ["chmod", "+x", "/docker-entrypoint.sh"]
# ENTRYPOINT ["/docker-entrypoint.sh"]


RUN cp /etc/kong/kong.conf.default /etc/kong/kong.conf

docker-entrypoint.sh

#!/usr/bin/env bash

echo "Hello World"

我也有一个docker-compose文件。

version: "3.8"

networks:
 kong-net:
  name: kong-net
  driver: bridge
  ipam:
    config:
      - subnet: 172.1.1.0/24

services:
  kong:
    container_name: kong
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    networks:
      kong-net:
        ipv4_address: 172.1.1.40
    healthcheck:
      test: [ “CMD”, “curl”, “-f”, “http://kong:8000” ]
      interval: 5s
      timeout: 2s
      retries: 15
    environment:
      - KONG_DATABASE=off
      - KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
      - KONG_PROXY_ACCESS_LOG=/dev/stdout
      - KONG_ADMIN_ACCESS_LOG=/dev/stdout
      - KONG_PROXY_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_ERROR_LOG=/dev/stderr
      - KONG_DECLARATIVE_CONFIG=/kong/declarative/kong.yml
      - MYNAME=amin
    ports:
      - "8444:8444"
      - "80:8000"
      - "443:8443"
      - "8001:8001"

我还有一个docker-compose文件,如下面,当我运行docker-composes-build时, 它按预期运行良好,但是如果我输入docker-file 中的三行和运行docker-compose-build这是结果

我做错了什么?我应该如何解决? 在启动之前,我需要在运行阶段的Docker容器中运行一个命令。我应该怎么做?

I have a docker file as below:

FROM kong
USER 0

RUN mkdir -p /kong/declarative/
COPY declarative/kong.yml /kong/declarative/

# COPY docker-entrypoint.sh /docker-entrypoint.sh
# RUN ["chmod", "+x", "/docker-entrypoint.sh"]
# ENTRYPOINT ["/docker-entrypoint.sh"]


RUN cp /etc/kong/kong.conf.default /etc/kong/kong.conf

and the docker-entrypoint.sh is

#!/usr/bin/env bash

echo "Hello World"

also I have a docker-compose file as below

version: "3.8"

networks:
 kong-net:
  name: kong-net
  driver: bridge
  ipam:
    config:
      - subnet: 172.1.1.0/24

services:
  kong:
    container_name: kong
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    networks:
      kong-net:
        ipv4_address: 172.1.1.40
    healthcheck:
      test: [ “CMD”, “curl”, “-f”, “http://kong:8000” ]
      interval: 5s
      timeout: 2s
      retries: 15
    environment:
      - KONG_DATABASE=off
      - KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
      - KONG_PROXY_ACCESS_LOG=/dev/stdout
      - KONG_ADMIN_ACCESS_LOG=/dev/stdout
      - KONG_PROXY_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_ERROR_LOG=/dev/stderr
      - KONG_DECLARATIVE_CONFIG=/kong/declarative/kong.yml
      - MYNAME=amin
    ports:
      - "8444:8444"
      - "80:8000"
      - "443:8443"
      - "8001:8001"

When I run docker-compose up --build it runs fine as expected but if I uncomment the three lines in the docker-file and run docker-compose up --build this is the result

enter image description here

What is it that I am doing wrong? How should I fix it?
I need to run a command in the docker container in the run stage before it is started. How should I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文