public async Task InitVaultContainer() { var registryImage = await dockerWrapper.FindImage(repoTag); using (var client = dockerWrapper.GetClient()) { var p = new CreateContainerParameters(); p.Image = registryImage.ID; //p.Volumes = new Dictionary<string, EmptyStruct>(); //p.Volumes.Add("/certs:/certs", new EmptyStruct()); p.ExposedPorts = new Dictionary <string, EmptyStruct>(); p.HostConfig = new HostConfig(); p.HostConfig.CapAdd = new List <string> { "IPC_LOCK" }; p.HostConfig.PortBindings = new Dictionary <string, IList <PortBinding> >(); p.HostConfig.PortBindings.Add("8200/tcp", new List <PortBinding> { new PortBinding() { HostIP = "0.0.0.0", HostPort = "8200" } }); p.Env = new List <string>() { "VAULT_DEV_ROOT_TOKEN_ID=myroottoken" }; p.Name = containerName; var containerResponse = await client.Containers.CreateContainerAsync(p); var startP = new ContainerStartParameters(); await client.Containers.StartContainerAsync(containerResponse.ID, startP); } }
public async Task Publish() { Console.WriteLine("Publish"); // https://stackoverflow.com/questions/28349392/how-to-push-a-docker-image-to-a-private-repository //docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG] //Then docker push using that same tag. //docker push NAME[:TAG] using (var client = dockerWrapper.GetClient()) { var parameters = new ImageTagParameters(); parameters.RepositoryName = "privateregistry.mynetwork.local:5443/" + ImageName; parameters.Tag = "1"; Console.WriteLine("Tag"); await client.Images.TagImageAsync(ImageName + ":1", parameters); Console.WriteLine("try to find : " + ImageName + ":1"); var foundImage = await dockerWrapper.FindImage(ImageName + ":1"); var p = new ImagePushParameters(); p.ImageID = foundImage.ID; p.Tag = "1"; var progress = new DockerProgress(m => { if (m.Progress != null) { Console.WriteLine(m.ID + " " + m.ProgressMessage /*+ " : " + m.Progress.Current + "/" + m.Progress.Total*/); } }); var authConfig = new AuthConfig(); await client.Images.PushImageAsync("privateregistry.mynetwork.local:5443/" + ImageName + ":1", p, authConfig, progress); } }
public async Task Install() { // Image is alrady used by the mirror registry await dockerWrapper.CreateImageIfNotFound(repoTag); var registryImage = await dockerWrapper.FindImage(repoTag); using (var client = dockerWrapper.GetClient()) { /* * https://docs.docker.com/registry/deploying/#get-a-certificate * * docker run -d \ * --restart=always \ * * docker run \ * --name privateregistry \ * -v ${HOME}/cidata/privateregistry/var/lib/registry:/var/lib/registry \ * -v ${HOME}/cidata/privateregistry/certs:/certs \ * -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \ * -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/privateregistry.mynetwork.local.crt \ * -e REGISTRY_HTTP_TLS_KEY=/certs/privateregistry.mynetwork.local.key \ * -p 5443:443 \ * registry:2 */ // copy tls keys shellHelper.Bash($"rm -rf {cidataDir}/privateregistry/certs"); shellHelper.Bash($"mkdir -p {cidataDir}/privateregistry/certs"); shellHelper.Bash($"cp {cidataDir}/tls/privateregistry.mynetwork.local.* {cidataDir}/privateregistry/certs"); // Registry data outside the container in /privateregistry shellHelper.Bash("mkdir -p {cidataDir}/privateregistry/var/lib/registry"); var infraCidata = "/cidata"; var p = new CreateContainerParameters(); p.Image = registryImage.ID; p.ExposedPorts = new Dictionary <string, EmptyStruct>(); p.ExposedPorts.Add("443/tcp", new EmptyStruct()); p.Env = new List <string>() { "REGISTRY_HTTP_ADDR=0.0.0.0:443", "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/privateregistry.mynetwork.local.crt", "REGISTRY_HTTP_TLS_KEY=/certs/privateregistry.mynetwork.local.key", "REGISTRY_STORAGE_DELETE_ENABLED=true" }; p.Name = "privateregistry"; p.HostConfig = new DockerHostConfig() .Bind($"{infraCidata}/privateregistry/var/lib/registry:/var/lib/registry") .Bind($"{infraCidata}/privateregistry/certs:/certs") .PortBinding("0.0.0.0", "5443", "443/tcp") .RestartAlways() .GetConfig(); var response = await client.Containers.CreateContainerAsync(p); var p2 = new ContainerStartParameters(); await client.Containers.StartContainerAsync(response.ID, p2); } }