如何在后台使用Dockerfile中的自定义入口点运行docker容器
我已经创建了下面的docker 内容包括 当我从docker文件构建docker映像时,它是否已成功创建。 然后我使用下面的命令将docker映像作为容器运行如何在后台使用Dockerfile中的自定义入口点运行docker容器,docker,dockerfile,Docker,Dockerfile,我已经创建了下面的docker 内容包括 当我从docker文件构建docker映像时,它是否已成功创建。 然后我使用下面的命令将docker映像作为容器运行 docker run -d --name ethereum-ubuntu-geth-node2 ethereum-ubuntu-geth-node2 它创建容器并立即退出容器。我并不期望这样,因为我正在守护进程模式下运行容器(它应该在后台运行) 以下是容器状态 $ docker ps -a CONTAINER ID IM
docker run -d --name ethereum-ubuntu-geth-node2 ethereum-ubuntu-geth-node2
它创建容器并立即退出容器。我并不期望这样,因为我正在守护进程模式下运行容器(它应该在后台运行)
以下是容器状态
$ docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
0d25a5e71449 ethereum-ubuntu-geth-node2 "entry-point.sh"
4 seconds ago Exited (0) 1 second ago
ethereum-ubuntu-geth-node2
下面是容器日志的输出
$ docker logs ethereum-ubuntu-geth-node2
WARN [09-28|00:32:28] No etherbase set and no accounts found as default
INFO [09-28|00:32:28] Allocated cache and file handles database=/home/ubuntu/eth-dev/geth/chaindata cache=16 handles=16
INFO [09-28|00:32:28] Writing custom genesis block
INFO [09-28|00:32:28] Successfully wrote genesis state database=chaindata hash=a3c5c1…d6926b
INFO [09-28|00:32:28] Allocated cache and file handles database=/home/ubuntu/eth-dev/geth/lightchaindata cache=16 handles=16
INFO [09-28|00:32:28] Writing custom genesis block
INFO [09-28|00:32:28] Successfully wrote genesis state database=lightchaindata hash=a3c5c1…d6926b
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.1-unstable/linux-amd64/go1.9
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0
rpc:1.0 txpool:1.0 web3:1.0
下面是docker运行交互输出的输出
$ docker run -it --name ethereum-ubuntu-geth-node2 ethereum-ubuntu-geth-node2
WARN [09-28|00:45:28] No etherbase set and no accounts found as default
INFO [09-28|00:45:28] Allocated cache and file handles database=/home/ubuntu/eth-dev/geth/chaindata cache=16 handles=16
INFO [09-28|00:45:28] Writing custom genesis block
INFO [09-28|00:45:28] Successfully wrote genesis state database=chaindata hash=a3c5c1…d6926b
INFO [09-28|00:45:28] Allocated cache and file handles database=/home/ubuntu/eth-dev/geth/lightchaindata cache=16 handles=16
INFO [09-28|00:45:28] Writing custom genesis block
INFO [09-28|00:45:28] Successfully wrote genesis state database=lightchaindata hash=a3c5c1…d6926b
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.1-unstable/linux-amd64/go1.9
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0
rpc:1.0 txpool:1.0 web3:1.0
>
现在,当我检查容器状态时,它已启动
$ docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
e27de43da867 ethereum-ubuntu-geth-node2 "entry-point.sh"
12 seconds ago Up 11 seconds 8545-8546/tcp, 30303/tcp,
30303/udp ethereum-ubuntu-geth-node2
下面是我的docker详细信息
$ docker version
Client:
Version: 17.09.0-ce-rc2
API version: 1.32
Go version: go1.8.3
Git commit: 363a3e7
Built: Thu Sep 14 02:01:59 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce-rc2
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: 363a3e7
Built: Thu Sep 14 02:03:24 2017
OS/Arch: linux/amd64
Experimental: false
一旦容器启动,我想在shell中执行一些
geth
utilities命令,一旦我退出shell,我仍然希望容器能够运行。我可以这样做吗?您可以运行一个同时定义和分离了stdin的容器。不过,最好将应用程序配置为在前台作为服务器运行,而不需要stdin
$ docker run -itd \
--name ethereum-ubuntu-geth-node2 \
ethereum-ubuntu-geth-node2
对我试过了。但是我没有得到交互式shell。容器是否立即退出?实际上我想做一些
geth
实用程序,然后退出shell,但容器要运行。我可以这样做吗?容器是一种运行带有附加隔离(名称空间和cgroup)的进程的方法。如果您退出入口点,那么您已经退出了流程,并且不再有正在运行的容器。
$ docker version
Client:
Version: 17.09.0-ce-rc2
API version: 1.32
Go version: go1.8.3
Git commit: 363a3e7
Built: Thu Sep 14 02:01:59 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce-rc2
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: 363a3e7
Built: Thu Sep 14 02:03:24 2017
OS/Arch: linux/amd64
Experimental: false
$ docker run -itd \
--name ethereum-ubuntu-geth-node2 \
ethereum-ubuntu-geth-node2