2017-09-28 1 views
0

J'ai créé le docker ci-dessous file.comment exécuter conteneur docker en arrière-plan avec entrypoint personnalisé dans Dockerfile

FROM ubuntu:latest as builder 

ENV DEBIAN_FRONTEND=noninteractive \ 
INITRD=No \ 
LANG=en_US.UTF-8 \ 
GOVERSION=1.9 \ 
GOROOT=/opt/go \ 
GOPATH=/root/.go 
RUN apt-get update \ 
    && apt-get install -y software-properties-common \ 
&& apt-get install -y wget \ 
&& apt-get install -y make \ 
&& rm -rf /var/lib/apt/lists/* \ 
&& add-apt-repository ppa:jonathonf/gcc-7.2 \ 
&& apt-get update \ 
&& apt-get install -y gcc g++ \ 
&& apt-get install -y linux-headers-4.11.0-14-generic \ 
&& apt-get install -y musl-dev \ 
&& cd /opt && wget https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz && \ 
tar zxf go${GOVERSION}.linux-amd64.tar.gz && rm go${GOVERSION}.linux-amd64.tar.gz && \ 
ln -s /opt/go/bin/go /usr/bin/ && \ 
mkdir $GOPATH 

ADD . /go-ethereum 
RUN mkdir -p /usr/local/config \ 
    && mkdir -p /home/ubuntu/eth-dev \ 
    && mkdir -p /usr/local/scripts \ 
    && cd /go-ethereum && make geth 

COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ 
COPY --from=builder /go-ethereum/scripts/entry-point.sh /usr/local/bin/ 
COPY --from=builder /go-ethereum/genesis/genesis.json /usr/local/config/ 

EXPOSE 8545 8546 30303 30303/udp 
ENTRYPOINT ["entry-point.sh"] 

Le contenu de entry-point.sh sont

#!/bin/bash 
geth --datadir /home/ubuntu/eth-dev init /usr/local/config/genesis.json 

geth --networkid 45634 --verbosity 4 --ipcdisable --rpc --port 30301 --rpcport 8545 --rpcaddr 0.0.0.0 console 2>> /home/ubuntu/eth-dev/eth.log 

Lorsque je construis l'image docker du fichier docker est-il créé avec succès. J'exécuter l'image docker comme conteneur en utilisant la commande ci-dessous

docker run -d --name ethereum-ubuntu-geth-node2 ethereum-ubuntu-geth-node2 

Il crée le conteneur et sort du récipient immédiatement. Je ne m'attends pas à cela car je cours le conteneur en mode démon (il devrait fonctionner en arrière-plan).

est inférieur au statut de récipient

$ 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 

Ci-dessous, la sortie des billes de conteneurs.

$ 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 

est inférieure à la sortie de docker exécuter la sortie interactive.

$ 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 

> 

Maintenant, lorsque je vérifie l'état du conteneur, il est en hausse.

$ 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 

Ci-dessous mes détails pour les débardeurs.

$ 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 

Je veux faire quelques commande geth utilitaires dans la coque une fois que le réservoir a commencé et une fois que je quitte la coquille attendant toujours le récipient à en cours d'exécution. Puis-je faire ça de toute façon?

Répondre

1

Vous pouvez exécuter un conteneur avec stdin défini et détaché en même temps. Bien qu'il soit préférable de configurer votre application pour qu'elle fonctionne en tant que serveur au premier plan sans avoir besoin de stdin.

$ docker run -itd \ 
    --name ethereum-ubuntu-geth-node2 \ 
    ethereum-ubuntu-geth-node2 
+0

Oui. Je l'ai essayé. Mais je n'ai pas eu de shell interactif. –

+0

Le conteneur a-t-il immédiatement quitté? – BMitch

+0

non. Le conteneur est en cours d'exécution en arrière-plan. –