Run the ASPDOTNETCOREMVC program on Docker-part2: Modify the container and publish the image

Source: Internet
Author: User
Tags dotnet docker ps docker cp docker hub

in the previous part " Run the ASPDOTNETCOREMVC program on Docker-part1 , has successfully run the Aspdotnetcore program in two different containers, the contents of the two containers are exactly the same, but the external access port is different.

Modify container contents

Next look at how to modify the contents of the container, so that the contents of the two container display a little different.

In fact, each container has its own independent file system, of course, can be implemented to modify their own content, while modifying the contents of the container will not affect the mirror, you can interpret the image as read-only, but the contents of the container is writable.

Before you modify a file, make sure that two containers are already running

Execute Start command

Docker Start App1 app2

See if you're already running

Docker Ps–a

Open the program on the development machine, locate the Views/home directory, open the index.cshtml file

Change the content of the H4 label to something else by simply changing the title's display

Since the site content that was generated by dotnet publish was not a view folder, it was compiled into AspDotNetCoreMvcDocker.PrecompiledViews.dll (page precompilation). So when we're done, we're going to re-execute dotnet Publish, generate a new site content, and then update the file to the Docker container.

The AspDotNetCoreMvcDocker.PrecompiledViews.dll is uploaded to the server where Docker is located (as ignored by the development machine) after rebuilding

Execute the following command in the directory containing the file

Docker CP./aspdotnetcoremvcdocker.precompiledviews.dll app1:/app/

The above command is to copy the AspDotNetCoreMvcDocker.PrecompiledViews.dll file from the host machine to the/app folder of the container App1

Performing Docker restart App1

Then open the browser http://{ip}:3000 will see the title background color and the title has changed

and http://{ip}:4000 's page is the previous content.

Indicates that the file system of the container is independent.

Submit Mirror Changes

based on the above changes, we can create a new image, Use the Docker commit command to create a new image.

Docker Commit App1 Shenba/aspdotnetcoremvc:changed

running docker images, you can see the following output

REPOSITORY TAG IMAGE ID CREATED SIZE

SHENBA/ASPDOTNETCOREMVC changed 4ec1f62d8f06 minutes ago 284MB

SHENBA/ASPDOTNETCOREMVC latest 407471EF91F2 2 weeks ago 284MB

Can see our new image shenba/aspdotnetcoremvc:changed, it is actually created based on the SHENBA/ASPDOTNETCOREMVC image, but the corresponding tag becomes the changed.

push image published to Docker Hub

Publishing a locally created custom image to the Docker Hub is similar to exposing the source code to GitHub and exposing the image to the Web.

Of course, before you push, you must register a user name on the Docker hub, in detail, very simple.

Notice that Docker's username must be used as a prefix for the name of the Docker image, such as the image I created here is the username for my Docker hub, followed by/Shenba/aspdotnetcoremvc,shenba the name, This is combined into a mirror name.

Start push, first login with username and password

Docker Login-u < Your user name >-p < password >

After successful login, you will see the following prompt

Login succeeded

Once the login is successful, subsequent operations do not need to be logged in again.

Continue to push our image, which pushes the changed and latest two different tag images

Docker Push shenba/aspdotnetcoremvc:changed

Docker Push Shenba/aspdotnetcoremvc:latest

After the command has been executed successfully, you can see the push-up image under the Docker Hub's own account, which contains two tags

After execution, you can exit the login status by executing the following command

Docker Logout

Run the ASPDOTNETCOREMVC program on Docker-part2: Modify the container and publish the image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.