我有一个标记为me/my-image的docker镜像,我在dockerhub上有一个名为me-private的私有 repo。 当我推送me/my-image的时候,我最终总是撞到公共 repo。
要把我的图像推送到我的私人 repo,具体的语法是什么?
你需要先用你的 "registryhost "正确标记你的图片。
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
然后使用相同的标签进行docker推送。
docker push NAME[:TAG]
例子。
docker tag 518a41981a6a myRegistry.com/myImage
docker push myRegistry.com/myImage
只需简单的三步。
docker login --username username
。--password
,就会提示你输入密码,建议这样做,因为它不会存储在你的命令历史中。docker tag my-image username/my-repo
。
docker push username/my-repo
。
首先进入你的Docker Hub账户,制作 repo。下面是我的Docker Hub账户的截图。 ![在此输入图片描述][1] 。
从图片中,你可以看到我的 repo 是 "chuangg"。
现在进入 repo,通过点击你的图像名称使其成为私有。对我来说,我点击了 "chuangg/gene_commited_image",然后我进入设置-> 使之成为私有。然后我按照屏幕上的指示 ![在此输入图像描述][2] 。
如何将你的docker镜像上传到docker hub?
方法#1=通过命令行(cli)推送你的镜像
docker commit <container ID> <repo name>/<你想给镜像的名字>
。是的,我认为它必须是容器ID。它可能不能是镜像的ID。
例如= docker commit 99e078826312 chuangg/gene_commited_image
。
docker run -it chaung/gene_commited_image
。
docker login --username=<user username> --password=<user password>
。
例如= docker login --username=chuangg [email protected]
。
是的,你必须先登录。使用 "docker logout "注销
docker push chuangg/gene_commited_image
。**方法#2=使用pom.xml和命令行推送你的图像。
注意,我使用了一个名为 "build-docker "的Maven配置文件。如果你不想使用配置文件,只需删除<profiles>、<profile>和<id>build-docker</id>
元素。
在父级的pom.xml里面。
<profiles>
<profile>
<id>build-docker</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.18.1</version>
<configuration>
<images>
<image>
<name>chuangg/gene_project</name>
<alias>${docker.container.name}</alias>
<!-- Configure build settings -->
<build>
<dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir>
<assembly>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}\target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
部署Docker镜像的Docker终端命令(从pom.xml所在的目录)= mvn clean deploy -Pbuild-docker docker:push
。
注意,方法#2和#3的区别是,方法#3有一个额外的<执行>
用于部署。
方法#3=使用Maven自动部署到Docker Hub。
把这些东西添加到你的父级pom.xml中。
<distributionManagement>
<repository>
<id>gene</id>
<name>chuangg</name>
<uniqueVersion>false</uniqueVersion>
<layout>legacy</layout>
<url>https://index.docker.io/v1/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>build-docker</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.18.1</version>
<configuration>
<images>
<image>
<name>chuangg/gene_project1</name>
<alias>${docker.container.name}</alias>
<!-- Configure build settings -->
<build>
<dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir>
<assembly>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}\target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker:push</id>
<phase>install</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
到C:\Users\Gene.docker\目录,把这个添加到你的config.json文件。 ![在此输入图片描述][3] 。
现在在你的Docker快速启动终端键入= mvn clean install -Pbuild-docker
。
对于没有使用Maven Profiles的用户,只需输入mvn clean install
即可。
以下是成功信息的截图。 ![在此输入图片描述][4] 。
这是我的完整pom.xml和目录结构的截图。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gene.app</groupId>
<artifactId>VendingMachineDockerMavenPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>www.gene.com</url>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.gene.sample.Customer_View</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>gene</id>
<name>chuangg</name>
<uniqueVersion>false</uniqueVersion>
<layout>legacy</layout>
<url>https://index.docker.io/v1/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>build-docker</id>
<properties>
<java.docker.version>1.8.0</java.docker.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.18.1</version>
<configuration>
<images>
<image>
<name>chuangg/gene_project1</name>
<alias>${docker.container.name}</alias>
<!-- Configure build settings -->
<build>
<dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir>
<assembly>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}\target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker:push</id>
<phase>install</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
这里是我的Docker文件。
FROM java:8
MAINTAINER Gene Chuang
RUN echo Running Dockerfile in src/docker/vending_machine_emulator/Dockerfile directory
ADD maven/VendingMachineDockerMavenPlugin-1.0-SNAPSHOT.jar /bullshitDirectory/gene-app-1.0-SNAPSHOT.jar
CMD ["java", "-classpath", "/bullshitDirectory/gene-app-1.0-SNAPSHOT.jar", "com/gene/sample/Customer_View" ]
错误#1的解决方案= 不要将<执行>
与maven部署阶段同步,因为这样maven就会尝试部署2倍的镜像,并在jar上加一个时间戳。这就是为什么我使用<阶段>安装</阶段>
。
如果你的docker注册表是私有的,并且是自我托管的,你应该做以下工作。
docker login <REGISTRY_HOST>:<REGISTRY_PORT>
docker tag <IMAGE_ID> <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>
docker push <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>
例:
docker login repo.company.com:3456
docker tag 19fcc4aa71ba repo.company.com:3456/myapp:0.1
docker push repo.company.com:3456/myapp:0.1
。
docker login repo.company.com:3456
docker tag 19fcc4aa71ba repo.company.com:3456/myapp:0.1
docker push repo.company.com:3456/myapp:0.1
有两个选择。
1.进入中心,先创建版本库,并将其标记为私有。然后当你推送到该版本时,它将是私有的。这是最常见的方法。
2.登录你的docker hub账户,并进入你的全局设置。有一个设置允许你设置你推送的仓库的默认可见性。默认情况下,它被设置为公开,但如果你把它改为私有,你推送的所有仓库都会被默认标记为私有。值得注意的是,你需要在你的账户上有足够的私有仓库,否则仓库将被锁定,直到你升级你的计划。
在dockerhub上创建仓库。
$docker tag IMAGE_ID UsernameOnDockerhub/repoNameOnDockerhub:last
。
$docker push UsernameOnDockerhub/repoNameOnDockerhub:last
。
注:这里。 "repoNameOnDockerhub"。 : 您所提到的名称的仓库有 在dockerhub上出现
"最新"。 |
---|
只是标签 |
参考文献: [dock.docker.com]() dock.docker.com
本主题提供了有关部署和配置注册表的基本信息。
在部署注册表之前,你需要在主机上安装Docker。
使用类似下面的命令来启动注册表容器。
start_registry.sh
#!/bin/bash
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v /data/registry:/var/lib/registry \
registry:2
ubuntu:16.04
镜像。$ docker pull ubuntu:16.04
localhost:5000/my-ubuntu
。
这将为现有的镜像创建一个额外的标签。
当标签的第一部分是主机名和端口时,Docker在推送时将其解释为注册表的位置。$ docker tag ubuntu:16.04 localhost:5000/my-ubuntu
localhost:5000
的本地注册表。$ docker push localhost:5000/my-ubuntu
localhost:5000/my-ubuntu
镜像。$ docker image remove ubuntu:16.04 $ docker image remove localhost:5000/my-ubuntu
localhost:5000/my-ubuntu
镜像。$ docker pull localhost:5000/my-ubuntu
根据docs.docker.com,这是非常不安全的,不建议**。
daemon.json
文件,在Linux上,它的默认位置是/etc/docker/daemon.json
,在Windows Server上,它的默认位置是C:/\ProgramData/docker\config\daemon.json
。
如果你使用Docker for Mac
或Docker for Windows
,点击Docker图标->。 Preferences -> Daemon
,在insecure注册表
中添加。如果daemon.json
文件不存在,就创建它。
假设文件中没有其他设置,它应该有以下内容。
{ "不安全的注册"。 : ["myregistrydomain.com:5000"] }
在启用了不安全注册表的情况下,Docker会经过以下步骤。
> docker login [OPTIONS] [SERVER]
[OPTIONS]:
-u username
-p password
例如:
> docker login localhost:8080
。
> docker login localhost:8080
> docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
例如:
> docker tag myApp:v1 localhost:8080/myname/myApp:v1
。
> docker tag myApp:v1 localhost:8080/myname/myApp:v1
>docker push [OPTIONS] NAME[:TAG]
例如:
> docker push localhost:8080/myname/myApp:v1
。
> docker push localhost:8080/myname/myApp:v1
[1]: https://docs.docker.com/engine/reference/commandline/cli/
简单的工作解决方案。
到这里https://hub.docker.com/
创建一个PRIVATE repository,名称比如johnsmith/private-repository
这就是你在构建镜像时要用到的NAME/REPOSITORY
。
首先,"docker登录"。
其次,我使用"docker build -t johnsmith/private-repository:01 .
"
(其中01是我的版本名)来创建镜像,然后我使用"docker images
"
来确认创建的镜像,比如下面这个黄框。
(抱歉,我不能粘贴表格格式,只能粘贴文本字符串)
>.Johnsmith/privaterepository(repository)01(TAG)c5f4a2861d6(IMAGE ID)2天前(CREATED 305MB(SIZE))。 johnsmith/private-repository(REPOSITORY) 01(TAG) c5f4a2861d6e(IMAGE ID) 2天前(CREATED) 305MB(SIZE)
docker push johnsmith/private-repository:01
(你的私有仓库将在这里,例如https://hub.docker.com/r/johnsmith/private-repository/)。好了!