2015-09-23 55 views
1

我只是想建立我Dockerfile,看下面:如何運行並登錄到容器進行調試?

FROM ubuntu:14.04 
MAINTAINER Mike Dillon <[email protected]> 

ENV POSTGIS_MAJOR 2.1 
ENV POSTGIS_VERSION 2.1.7+dfsg-3~94.git954a8d0.pgdg80+1 
# temporary instruction, i beleive all the apt-get etc commands will need to be RUN in the 
# RUN -t -i ubuntu:14.04 /bin/bash 

RUN apt-get install postgresql-client 
RUN apt-get update && apt-get install -y --no-install-recommends postgresql-$PG_MAJOR-po$ 
postgis=$POSTGIS_VERSION && rm -rf /var/lib/apt/lists/* 

RUN mkdir -p /docker-entrypoint-initdb.d 
COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/postgis.sh 

現在的幾行代碼的運行,比我得到以下錯誤:

Need to get 2538 kB of archives. 
After this operation, 12.3 MB of additional disk space will be used. 
Do you want to continue? [Y/n] Abort. 
The command '/bin/sh -c apt-get install postgresql-client' returned a non-zero code: 1 

現在我不關心Dockerfile和錯誤,事實上我知道錯誤是什麼,我沒有將-y標誌添加到RUN apt-get install postgresql-client命令中。我的問題是有關調試的,我的同事給了我下面的建議遵循每次我得到一個錯誤,當我試圖建立一個Dockerfile:

The non-zero code means that there was an error running this task. To test exactly what's wrong, you can run and login the container, and run this command manually inside the container.

現在,我怎麼run and login the container?我不太瞭解那部分,有人可以解釋嗎?

回答

4

假設您運行構建並有問題。碼頭工人提供您可以登錄的圖層ID來執行故障排除。

$ docker build -t test . 
Sending build context to Docker daemon 2.56 kB 
Step 0 : FROM ubuntu:14.04 
---> 8251da35e7a7 
Step 1 : MAINTAINER Mike Dillon <[email protected]> 
---> Running in 85fd1216cc35 
---> d6d68fed500b 
Removing intermediate container 85fd1216cc35 
Step 2 : ENV POSTGIS_MAJOR 2.1 
---> Running in 6d0ee92229ee 
---> 377a352cd0fa 
Removing intermediate container 6d0ee92229ee 
Step 3 : ENV POSTGIS_VERSION 2.1.7+dfsg-3~94.git954a8d0.pgdg80+1 
---> Running in 40173fe1edb9 
---> 758a2e6c90b0 
Removing intermediate container 40173fe1edb9 
Step 4 : RUN apt-get install postgresql-client 
---> Running in 3ece9c7fa9df 
Reading package lists... 
Building dependency tree... 
Reading state information... 
The following extra packages will be installed: 
    krb5-locales libasn1-8-heimdal libedit2 libgssapi-krb5-2 libgssapi3-heimdal 
    libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal 
    libhx509-5-heimdal libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 
    libkrb5support0 libldap-2.4-2 libpq5 libroken18-heimdal libsasl2-2 
    libsasl2-modules libsasl2-modules-db libwind0-heimdal postgresql-client-9.3 
    postgresql-client-common 
Suggested packages: 
    krb5-doc krb5-user libsasl2-modules-otp libsasl2-modules-ldap 
    libsasl2-modules-sql libsasl2-modules-gssapi-mit 
    libsasl2-modules-gssapi-heimdal postgresql-9.3 postgresql-doc-9.3 
The following NEW packages will be installed: 
    krb5-locales libasn1-8-heimdal libedit2 libgssapi-krb5-2 libgssapi3-heimdal 
    libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal 
    libhx509-5-heimdal libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 
    libkrb5support0 libldap-2.4-2 libpq5 libroken18-heimdal libsasl2-2 
    libsasl2-modules libsasl2-modules-db libwind0-heimdal postgresql-client 
    postgresql-client-9.3 postgresql-client-common 
0 upgraded, 24 newly installed, 0 to remove and 0 not upgraded. 
Need to get 2538 kB of archives. 
After this operation, 12.3 MB of additional disk space will be used. 
Do you want to continue? [Y/n] Abort. 
The command '/bin/sh -c apt-get install postgresql-client' returned a non-zero code: 1 

所以它停靠在集裝箱ID(3ece9c7fa9df),那麼你就需要與以前的容器(758a2e6c90b0)去登錄到測試命令:

$ docker run -ti 758a2e6c90b0 bash 
[email protected]:/# apt-get install postgresql-client 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
The following extra packages will be installed: 
    krb5-locales libasn1-8-heimdal libedit2 libgssapi-krb5-2 libgssapi3-heimdal 
    libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal 
    libhx509-5-heimdal libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 
    libkrb5support0 libldap-2.4-2 libpq5 libroken18-heimdal libsasl2-2 
    libsasl2-modules libsasl2-modules-db libwind0-heimdal postgresql-client-9.3 
    postgresql-client-common 
Suggested packages: 
    krb5-doc krb5-user libsasl2-modules-otp libsasl2-modules-ldap 
    libsasl2-modules-sql libsasl2-modules-gssapi-mit 
    libsasl2-modules-gssapi-heimdal postgresql-9.3 postgresql-doc-9.3 
The following NEW packages will be installed: 
    krb5-locales libasn1-8-heimdal libedit2 libgssapi-krb5-2 libgssapi3-heimdal 
    libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal 
    libhx509-5-heimdal libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 
    libkrb5support0 libldap-2.4-2 libpq5 libroken18-heimdal libsasl2-2 
    libsasl2-modules libsasl2-modules-db libwind0-heimdal postgresql-client 
    postgresql-client-9.3 postgresql-client-common 
0 upgraded, 24 newly installed, 0 to remove and 0 not upgraded. 
Need to get 2538 kB of archives. 
After this operation, 12.3 MB of additional disk space will be used. 
Do you want to continue? [Y/n] 

現在你看到確切的同樣的錯誤,重複這個問題,你可以運行任何你可以在該容器層進行故障排除的linux命令。你應該知道下一步該做什麼。

在這種情況下,當您手動運行該命令並且看到錯誤時,可以使用-y選項再次運行以證明問題可以得到解決。在其他情況下,例如在shell中啓用調試選項腳本,使用-x選項運行等。如果有幫助,您還可以瀏覽日誌文件。

+0

這有助於調試嗎?我仍然不明白,對不起問題! –

+1

這取決於。在這種情況下,當您手動運行該命令並且看到錯誤時,可以使用'-y'選項再次運行以證明問題可以得到解決。在其他情況下,例如在shell腳本中啓用調試選項,使用'-x'選項運行等。如果這有幫助,您還可以通過日誌文件。 – BMW

相關問題