Docker is a very handy platform when it comes to managing large-scale applications on your system. It provides a container-based unit for deploying necessary applications. You can install docker and create container users in your Linux operating system. In this article, I will illustrate how to create a user in Docker in Ubuntu not using a dockerfile.
- Installing Docker in Ubuntu.
- Downloading and creating docker container.
- Adding a new user to docker
- Need to be a root user or have root/sudo privileges to install Docker.
- Have Docker installed on Ubuntu.
- Need a Docker Container created on Ubuntu.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Create New User to Docker Container Without Docker File
A docker container stands for an environment that includes all the system tools, libraries, and settings to run software packages. It offers an OS-level infrastructure for uniform deployment and staging of applications. As it is similar to a virtualized OS environment, adding a new user to a docker container is also similar to adding a new user to the OS.
In this section, I will add a new docker container user called “jerry” to my Linux distribution, Ubuntu. To do the same, you can follow the process below.
Steps to Follow >
❶ Firstly, open the Ubuntu terminal.
❷ Then, log in to your docker container with the following command.
docker exec -it container-tom /bin/bash
❷ Now, run the following command to add a new user.
❸ Type a new password for your new user and press ENTER.
❹ Retype the password for confirmation and hit ENTER again.
❺ Continue pressing ENTER to skip the steps in the middle. However, you can give your desired information according to your need.
❻ Finally, type Y to confirm your given information.
❼ Now, to verify if the newly created user has access to your docker container, switch to the user account with the given command and press ENTER.
su - jerry
❽ Move to the tomcat folder by running the command below.
❾ Now, list all the tomcat container files to see if the new user has access or not.
In the image above, you can see that I have created a new docker user called “jerry” without using a docker file. You can check the new docker user account by switching to it and viewing the container files.
- How to Create Multiple Users in Linux? [2 Methods]
- Create a User in Ubuntu as Read-Only Access to Log Folder
- How to Create User Account in Ubuntu with Public Key
- Create A User in Ubuntu that Runs a Script and Logs Out [4 Steps]
Besides, knowing about creating a new Docker container user on Ubuntu, you will find the below information helpful.
Although your Ubuntu repository contains a docker package, but it may not be up to date. Therefore, to get the latest version I will download the docker package from the docker repository and install it on my system. Follow the instructions below to install the latest docker package.
Steps to Follow >
➊ At first, open your Ubuntu terminal.
➋ Update existing packages on your system with the command below and press ENTER.
sudo apt update
➌ Run the following command to install the prerequisite packages.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
❹ Then, run the given command to add the GPG key to your system
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
❺ Now, add the Docker repository to your APT sources.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
❻ To check if you are about to install docker from the docker repository run the following command.
apt-cache policy docker-ce
❼ Finally, install the docker environment by running the given command.
sudo apt install docker-ce
❽ Upon installing, you can check the docker status with the command below.
sudo systemctl status docker
In the above image, I have installed the Docker service on my machine by following the above-mentioned steps. To view the status of the Docker service you can utilize the systemctl command as shown above.
- How to Create an FTP User in Ubuntu? [Step-by-Step]
- Create a New SFTP User in Ubuntu with a New SSH Key
- How to Create Group and Add User in Ubuntu? [2 Cases]
- Create FTP User for Specific Directory in Ubuntu [4 Steps]
The docker environment where it provides OS-level virtualization for managing application packages is called a docker container. Containers are lightweight executable packages known as container images. These container images become docker containers when run on the docker engine.
In this section, I will create a docker container of the free and open-source server “Tomcat”. You can do the same by following the steps below.
Steps to Follow >
➊ At first, go to your Ubuntu terminal.
➋ Download the latest version of Tomcat docker image with the following command.
docker pull tomcat:latest
sudo docker ps -a
sudo docker run -d -p 8083:8083 --name container-tom 51c25da77baf
❺ Now, to view the available containers in your system, run the command below.
Upon completing the given steps, you can see that I have successfully created a tomcat docker container in my system and named it “container-tom”. You can view the created docker container information by running the “docker ps” command.
- How to Create a Jenkins User on Ubuntu? [2 Methods]
- How to Create MySQL User in Ubuntu? [2 Cases]
- Create User Without Home Directory in Ubuntu in Just 3 Steps
- How to Create a Root User in Ubuntu [Step-by-Step]
Running Docker As a Non-root User in Ubuntu
By default, a docker engine on your Linux OS can only be run as the root user. However, you can give access to running the docker engine to other users as well. In this example, I will enable my currently logged-in user to run docker. You can do the same by following the process below.
Steps to Follow >
➊ At first, launch the Ubuntu terminal.
➋ Now, run the following command on your command line.
sudo usermod -aG docker anonnya
➌ Finally, restart your system using the following command.
After restarting the system, you will be able to run the docker commands without the application of the sudo keyword. Therefore, you will have permission to run the docker engine as a regular user. In this case, my user account “anonnya” can run docker commands without the sudo keyword.
In this article, I have demonstrated the basic concepts of Docker container technology. This tutorial will enable you to install the Docker engine on your Linux machine and create a desired container from a specific docker image. After creating a docker container you will be able to add new users to it as per your requirement. I hope this article will help you get familiar with the Docker technology in Linux and improve your overall experience.
People Also Ask
- How to Create User and Add to Sudo in Ubuntu? [2 Methods]
- 2 Ways to Create a User With Access to a Drive in Ubuntu
- How to Create a New User in Ubuntu by GUI? [Step-by-Step]
- 2 Ways to Create User Account in Ubuntu Using Terminal
- How to Create Home Directory for Existing User in Ubuntu
- Create User with UID and GID in Ubuntu? [3 Scenarios]
- How to Create a Sudo User in Ubuntu? [Step-by-Step]