在利用Docker运行Tensorflow Jupyter时遇到了端口号无法开放到外网的情况,错误如下:

[andy@master andy]# nvidia-docker run -it -p 8888:8888 -v /andy/andy/:/notebooks/andy tensorflow:1.8.0-gpu 
WARNING: IPv4 forwarding is disabled. Networking will not work.
[I 09:04:03.467 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 09:04:03.480 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 09:04:03.487 NotebookApp] Serving notebooks from local directory: /notebooks
[I 09:04:03.488 NotebookApp] 0 active kernels
[I 09:04:03.488 NotebookApp] The Jupyter Notebook is running at:
[I 09:04:03.488 NotebookApp] http://[all ip addresses on your system]:8888/?token=389603956f0sd6e480f1520ac48e06fd03fab5b6589ff9a097
[I 09:04:03.488 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 09:04:03.488 NotebookApp] 
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=389603956f0sd6e480f1520ac48e06fd03fab5b6589ff9a097

后来制作镜像时遇到了同样的问题:

[root@master kubeflow]# sudo docker build -t jupyterandy:lasted .
Sending build context to Docker daemon 23.04 kB
Step 1/48 : FROM ubuntu:18.04@sha256:de774a3145f7ca4f0bd144c7d4ffb2931e06634f11529653b23eba85aef8e378
 ---> cd6d8154f1e1
Step 2/48 : ARG TF_PACKAGE=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.7.0-cp36-cp36m-linux_x86_64.whl
 ---> Using cache
 ---> 717397fac736
Step 3/48 : ARG TF_PACKAGE_PY_27=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.7.0-cp27-none-linux_x86_64.whl
 ---> Using cache
 ---> 1b4a91be6adb
Step 4/48 : ARG TF_SERVING_VERSION=0.0.0
 ---> Using cache
 ---> 4a8851a836e3
Step 5/48 : ARG TFMA_VERSION
 ---> Using cache
 ---> 50f5419a137c
Step 6/48 : ARG TFDV_VERSION
 ---> Using cache
 ---> 8625b6f1d541
Step 7/48 : ARG PIPELINE_SDK_PACKAGE=https://storage.googleapis.com/ml-pipeline/release/0.1.8/kfp.tar.gz
 ---> Using cache
 ---> 034818e518bb
Step 8/48 : USER root
 ---> Using cache
 ---> 1419e0dc1449
Step 9/48 : ENV DEBIAN_FRONTEND noninteractive
 ---> Using cache
 ---> 14d6ccee0ead
Step 10/48 : ENV NB_USER jovyan
 ---> Using cache
 ---> 1d96a7185474
Step 11/48 : ENV NB_UID 1000
 ---> Using cache
 ---> ba0433cc7663
Step 12/48 : ENV HOME /home/$NB_USER
 ---> Using cache
 ---> 6f29aa3bc765
Step 13/48 : ENV NB_PREFIX /
 ---> Using cache
 ---> 14f9c69f30aa
Step 14/48 : ENV CONDA_DIR /opt/conda
 ---> Using cache
 ---> a5099ba7d85e
Step 15/48 : ENV PATH $CONDA_DIR/bin:$PATH
 ---> Using cache
 ---> b29faba8850c
Step 16/48 : ENV TF_PACKAGE $TF_PACKAGE
 ---> Using cache
 ---> 2fbb397a65a4
Step 17/48 : ENV TF_PACKAGE_27 $TF_PACKAGE_PY_27
 ---> Using cache
 ---> 4978c1785813
Step 18/48 : ENV TF_SERVING_VERSION $TF_PACKAGE_PY_27
 ---> Using cache
 ---> 964a507ef780
Step 19/48 : ENV TFMA_VERSION $TFMA_VERSION
 ---> Using cache
 ---> fcab3a66975e
Step 20/48 : ENV TFDV_VERSION $TFDV_VERSION
 ---> Using cache
 ---> c39b081b9e94
Step 21/48 : ENV PIPELINE_SDK_PACKAGE $PIPELINE_SDK_PACKAGE
 ---> Using cache
 ---> 2a019d50a364
Step 22/48 : SHELL /bin/bash -c
 ---> Using cache
 ---> 83a5233df50b
Step 23/48 : RUN apt-get update && apt-get install -yq --no-install-recommends   apt-transport-https   build-essential   bzip2   ca-certificates   curl   g++   git   gnupg   graphviz   locales   lsb-release   openssh-client   sudo   unzip   vim   wget   zip   && apt-get clean &&   rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 6b97ff970e9d
Step 24/48 : ENV DOCKER_CREDENTIAL_GCR_VERSION 1.4.3
 ---> Using cache
 ---> b0af65a68598
Step 25/48 : RUN curl -LO https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v${DOCKER_CREDENTIAL_GCR_VERSION}/docker-credential-gcr_linux_amd64-${DOCKER_CREDENTIAL_GCR_VERSION}.tar.gz &&     tar -zxvf docker-credential-gcr_linux_amd64-${DOCKER_CREDENTIAL_GCR_VERSION}.tar.gz &&     mv docker-credential-gcr /usr/local/bin/docker-credential-gcr &&     rm docker-credential-gcr_linux_amd64-${DOCKER_CREDENTIAL_GCR_VERSION}.tar.gz &&     chmod +x /usr/local/bin/docker-credential-gcr
 ---> Using cache
 ---> 78a61a3bbed0
Step 26/48 : RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen &&     locale-gen
 ---> Using cache
 ---> 529a8c9d4baf
Step 27/48 : ENV LC_ALL en_US.UTF-8
 ---> Using cache
 ---> 2c6567323280
Step 28/48 : ENV LANG en_US.UTF-8
 ---> Using cache
 ---> 1138658fa36c
Step 29/48 : ENV LANGUAGE en_US.UTF-8
 ---> Using cache
 ---> 5a89a42ed36e
Step 30/48 : RUN useradd -M -s /bin/bash -N -u $NB_UID $NB_USER &&     chown -R ${NB_USER}:users /usr/local/bin &&     mkdir -p $HOME
 ---> Using cache
 ---> 9cb2694dd804
Step 31/48 : RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" &&     echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" > /etc/apt/sources.list.d/google-cloud-sdk.list &&     curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - &&     apt-get update &&     apt-get install -y google-cloud-sdk kubectl
 ---> [Warning] IPv4 forwarding is disabled. Networking will not work.
 ---> Running in 2d8542485b3f

倒数第二行的错误就是因为网络的问题无法下载相关软件,解决办法如下:

修改/etc/sysctl.conf文件,添加如下内容:

net.ipv4.ip_forward=1

然后重启网络:

systemctl restart network

查看是否添加成功:

sysctl net.ipv4.ip_forward

输出为1时则证明是成功的,

之后创建镜像和端口转发都没有问题了

如有问题请加技术交流群:526855734

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐