Docker 安装tensorflow

安装DOCKER1. https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/nstall from a packageIf you cannot use Docker’s repository to install Docker CE, you can download the .deb file for your release and install it manually. You will need to download a new file each time you want to upgrade Docker CE.
  • Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version, browse to pool/stable/ and choose amd64,armhf, or s390x. Download the .deb file for the Docker version you want to install.

    Note: To install an edge package, change the word stable in the URL to edge. Learn about stable and edge channels.

  • Install Docker CE, changing the path below to the path where you downloaded the Docker package.

    $ sudo dpkg -i /path/to/package.deb
    

    The Docker daemon starts automatically.

  • Verify that Docker CE is installed correctly by running the hello-world image.

    $ sudo docker run hello-world
    

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

  • Docker CE is installed and running. You need to use sudo to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps.2. https://github.com/widuu/chinese_docker/blob/master/installation/ubuntu.md#Ubuntu%E5%AE%89%E8%A3%85Docker##Ubuntu Docker可选配置这部分主要介绍了 Docker 的可选配置项,使用这些配置能够让 Docker 在 Ubuntu 上更好的工作。
  • 创建 Docker 用户组
  • 调整内存和交换空间(swap accounting)
  • 启用防火墙的端口转发(UFW)
  • 为 Docker 配置DNS服务
  • ###创建 Docker 用户组docker 进程通过监听一个 Unix Socket 来替代 TCP 端口。在默认情况下,docker 的 Unix Socket属于root用户,当然其他用户可以使用sudo方式来访问。因为这个原因, docker 进程就一直是root用户运行的。为了在使用 docker 命令的时候前边不再加sudo,我们需要创建一个叫 docker 的用户组,并且为用户组添加用户。然后在 docker 进程启动的时候,我们的 docker 群组有了 Unix Socket 的所有权,可以对 Socket 文件进行读写。

    注意:docker 群组就相当于root用户。有关系统安全影响的细节,请查看 Docker 进程表面攻击细节

    创建 docker 用户组并添加用户
  • 使用具有sudo权限的用户来登录你的Ubuntu。

    在这过程中,我们假设你已经登录了Ubuntu。

  • 创建 docker 用户组并添加用户。

     $ sudo usermod -aG docker ubuntu
    
  • 注销登录并重新登录

    这里要确保你运行用户的权限。

  • 验证 docker 用户不使用 sudo 命令开执行 Docker

     $ docker run hello-world
    
  • ###调整内存和交换空间(swap accounting)当我们使用 Docker 运行一个镜像的时候,我们可能会看到如下的信息提示:WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.、 为了防止以上错误信息提示的出现,我们需要在系统中启用内存和交换空间。我们需要修改系统的 GUN GRUB (GNU GRand Unified Bootloader) 来启用内存和交换空间。开启方法如下:
  • 使用具有sudo权限的用户来登录你的Ubuntu。

  • 设置 GRUB_CMDLINE_LINUX 的值如下:

     GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
    
  • 保存和关闭文件

  • 更新 GRUB

     $ sudo update-grub
    
  • 重启你的系统。

  • 3.GPU需+额外:https://medium.com/@gooshan/for-those-who-had-trouble-in-past-months-of-getting-google-s-tensorflow-to-work-inside-a-docker-9ec7a4df945bhttps://github.com/NVIDIA/nvidia-docker 3. Install Docker and nvidia-docker # Install docker
    curl -sSL https://get.docker.com/ | sh The docker container needs access to the GPU devices. For this purpose use `nvidia-docker` which is a wrapper around the standard `docker` command. # Install nvidia-docker and nvidia-docker-plugin wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.0-rc.3/nvidia-docker_1.0.0.rc.3-1_amd64.deb sudo dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb # Test nvidia-smi.
    nvidia-docker run --rm nvidia/cuda nvidia-smi You might need to use `nvidia-docker` with sudo! 安装Tensorflow1. https://medium.com/@gooshan/for-those-who-had-trouble-in-past-months-of-getting-google-s-tensorflow-to-work-inside-a-docker-9ec7a4df945b 4. Run a Tensorflow GPU-enable Docker container The container itself is started as pointed out in the official documentation as follows: # Run container
    nvidia-docker run -d --name -p 8888:8888 -p 6006:6006 gcr.io/tensorflow/tensorflow:latest-gpu # Log in
    nvidia-docker exec -it bash e.g.: nvidia-docker run -d --name tf1 -p 8888:8888 -p 6006:6006 gcr.io/tensorflow/tensorflow:latest-gpu nvidia-docker exec -it tf1 bash Note: Port 8888 is for ipython notebooks and port 6006 is for TensorBoard. You can test if everything is alright by running this Python script. https://www.tensorflow.org/install/install_linux#InstallingDocker GPU support Prior to installing TensorFlow with GPU support, ensure that your system meets all NVIDIA software requirements. To launch a Docker container with NVidia GPU support, enter a command of the following format:   $ nvidia-docker run -it -p hostPort:containerPort TensorFlowGPUImage where: 
  • -p hostPort:containerPort is optional. If you plan to run TensorFlow programs from the shell, omit this option. If you plan to run TensorFlow programs as Jupyter notebooks, set both hostPort and containerPort to 8888.
  • TensorFlowGPUImage specifies the Docker container. You must specify one of the following values:
    • gcr.io/tensorflow/tensorflow:latest-gpu, which is the latest TensorFlow GPU binary image.
    • gcr.io/tensorflow/tensorflow:latest-devel-gpu, which is the latest TensorFlow GPU Binary image plus source code.
    • gcr.io/tensorflow/tensorflow:version-gpu, which is the specified version (for example, 0.12.1) of the TensorFlow GPU binary image.
    • gcr.io/tensorflow/tensorflow:version-devel-gpu, which is the specified version (for example, 0.12.1) of the TensorFlow GPU binary image plus source code.
  •  We recommend installing one of the latest versions. For example, the following command launches the latest TensorFlow GPU binary image in a Docker container from which you can run TensorFlow programs in a shell:   $ nvidia-docker run -it gcr.io/tensorflow/tensorflow:latest-gpu bash The following command also launches the latest TensorFlow GPU binary image in a Docker container. In this Docker container, you can run TensorFlow programs in a Jupyter notebook:   $ nvidia-docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow:latest-gpu The following command installs an older TensorFlow version (0.12.1):   $ nvidia-docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow:0.12.1-gpu Docker will download the TensorFlow binary image the first time you launch it. For more details see the TensorFlow docker readme. Next Steps You should now validate your installation. 

    相关内容推荐