Docker,在包含“ubuntu:14.04”的容器中安装postgresql,在容器外面丢失

编程入门 行业动态 更新时间:2024-10-12 03:17:05
本文介绍了Docker,在包含“ubuntu:14.04”的容器中安装postgresql,在容器外面丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在容器中安装postgresql-9.3包含图像ubuntu:14:04

第一步,我做了图像ubuntu:14 :04

$ sudo Docker pull ubuntu:14.04

第二步,我用命令创建一个容器

$ sudo docker运行-t -i ubuntu:14.04 / bin / bash

第三步,我安装postgresql-容器中的9.3包含ubuntu:14.04(在包含ubuntu的容器中)

我试图进入postgresql可以,然后我试图找出容器,直接使用命令

#exit

我试图登录,容器postgresql我安装丢失,是否可以做和帮助解释为什么?

Docker本身,是否在内核中运行?

硬件>操作系统> Docker。

Docker概念: p>

Docker = images> Container

解决方案

您不应该在bash会话中安装任何内容。 由于docker使用 UnionFS(union filesystem service),一旦你退出了bash会话,任何修改都会丢失容器被删除。

您可以尝试退出容器的 docker commit ,但这不是如何你创建一个新的图像。

你所做的是创建一个名为 Dockerfile 的文本文件,其中你遵循类似的步骤如官方postgres图片 Dockerfile (除了你想从ubuntu开始)。

它包括:

运行apt-get update \ &&& apt-get install -y postgresql-common \ && sed -ri的/#(create_main_cluster)。* $ / \1 = false /'/etc/postgresql-common/createcluster.conf \ && apt-get install -y \ postgresql- $ PG_MAJOR = $ PG_VERSION \ postgresql-contrib- $ PG_MAJOR = $ PG_VERSION \ && rm -rf / var / lib / apt / lists / *

你运行 docker build -t mypostgres。:这将构建一个包含postgres的新图像。

换句话说,Dockerfile是在声明性文本文件中继续安装步骤,您可以随时从中构建图像。

I tried to install postgresql-9.3 in the container contains images "ubuntu: 14:04"

The first step, which I did make images "ubuntu: 14:04"

$ sudo Docker pull ubuntu:14.04

The second step, I create a container with the command

$ sudo docker run -t -i ubuntu:14.04 /bin/bash

The third step, I install postgresql-9.3 in a container contain "ubuntu:14.04" (in a container containing ubuntu)

I tried to get in postgresql could, then I tried to get out containers, straight out with the command

 # exit

I tried to log back in, the container postgresql I install missing, whether it can do and helped explain why?

Docker itself, whether running in the kernel?

Hardware> OS> Docker.

Docker concept:

Docker = images> Container

解决方案

You should not install anything in a bash session. Since docker uses UnionFS (union filesystem service), as soon as you exit your bash session, any modification is lost when the container is removed.

You could try a docker commit of your "Exited" container, but that is not how you build a new image.

What you do is create a text file named Dockerfile, in which you follow similar steps as the official postgres image Dockerfile (except you want to start from ubuntu).

It includes:

RUN apt-get update \ && apt-get install -y postgresql-common \ && sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \ && apt-get install -y \ postgresql-$PG_MAJOR=$PG_VERSION \ postgresql-contrib-$PG_MAJOR=$PG_VERSION \ && rm -rf /var/lib/apt/lists/*

You the run docker build -t mypostgres .: that will build a new image which will contain postgres.

In other words, the Dockerfile is there to persists the installation steps in a declarative text file, from which you can build an image at any time.

更多推荐

Docker,在包含“ubuntu:14.04”的容器中安装postgresql,在容器外面丢失

本文发布于:2023-10-29 00:19:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538178.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   ubuntu   Docker   postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!