{"id":1416,"date":"2024-11-08T05:35:12","date_gmt":"2024-11-08T05:35:12","guid":{"rendered":"https:\/\/kb.lagonet.vn\/?p=1416"},"modified":"2024-11-09T09:17:59","modified_gmt":"2024-11-09T09:17:59","slug":"create-an-ubuntu-20-04-docker-image-using-debootstrap","status":"publish","type":"post","link":"https:\/\/kb.lagonet.vn\/?p=1416","title":{"rendered":"Create an Ubuntu 20.04 Docker image using debootstrap"},"content":{"rendered":"\n<p>To create an Ubuntu 20.04 Docker image using <code>debootstrap<\/code>, follow these steps:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<p>Make sure you have the following installed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>debootstrap<\/code><\/li>\n\n\n\n<li><code>chroot<\/code><\/li>\n\n\n\n<li><code>tar<\/code><\/li>\n\n\n\n<li><code>docker<\/code><\/li>\n<\/ul>\n\n\n\n<p>You can install <code>debootstrap<\/code> on your system if it\u2019s not already there:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install debootstrap<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1. Create the Ubuntu 20.04 Root Filesystem with <code>debootstrap<\/code><\/h3>\n\n\n\n<p>Use <code>debootstrap<\/code> to create a minimal Ubuntu 20.04 filesystem in a local directory (e.g., <code>ubuntu-20.04<\/code>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo debootstrap --arch=amd64 focal ubuntu-20.04 http:\/\/archive.ubuntu.com\/ubuntu\/<\/code><\/pre>\n\n\n\n<p>This command downloads and installs a basic Ubuntu 20.04 environment into the <code>ubuntu-20.04<\/code> directory. The <code>--arch=amd64<\/code> option specifies the architecture, and <code>focal<\/code> is the codename for Ubuntu 20.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Configure the Filesystem (Optional)<\/h3>\n\n\n\n<p>You can perform additional configuration within the new root filesystem. For example, set up a basic <code>sources.list<\/code> for <code>apt<\/code> or install some packages.<\/p>\n\n\n\n<p>To enter the <code>chroot<\/code> environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chroot ubuntu-20.04<\/code><\/pre>\n\n\n\n<p>Inside <code>chroot<\/code>, you can set up a <code>sources.list<\/code> file or install any necessary packages. For example, to update the package list:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update<\/code><\/pre>\n\n\n\n<p>Once you&#8217;re done, exit the <code>chroot<\/code> environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Package the Filesystem as a TAR Archive<\/h3>\n\n\n\n<p>Next, create a tarball from the <code>ubuntu-20.04<\/code> directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tar -C ubuntu-20.04 -c . | sudo docker import - ubuntu:20.04<\/code><\/pre>\n\n\n\n<p>This command:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Uses <code>tar<\/code> to archive the contents of the <code>ubuntu-20.04<\/code> directory.<\/li>\n\n\n\n<li>Pipes the archive to Docker\u2019s <code>import<\/code> command.<\/li>\n\n\n\n<li>Tags the imported image as <code>ubuntu:20.04<\/code>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">4. Verify the Docker Image<\/h3>\n\n\n\n<p>You can verify that the image has been created by listing your Docker images:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker images<\/code><\/pre>\n\n\n\n<p>You should see <code>ubuntu<\/code> with the tag <code>20.04<\/code> in the list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Run a Container from the Image<\/h3>\n\n\n\n<p>To test the new image, run a container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -it ubuntu:20.04 \/bin\/bash<\/code><\/pre>\n\n\n\n<p>You should now be inside a running container based on your custom Ubuntu 20.04 image created with <code>debootstrap<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To create an Ubuntu 20.04 Docker image using debootstrap, follow these steps: Prerequisites Make sure you have the following installed: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[141,142],"tags":[],"class_list":["post-1416","post","type-post","status-publish","format-standard","hentry","category-devops","category-docker"],"_links":{"self":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1416"}],"version-history":[{"count":1,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1416\/revisions"}],"predecessor-version":[{"id":1417,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1416\/revisions\/1417"}],"wp:attachment":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}