Linux Activity Worksheets

Linux Lab Worksheet: Managing Users and Directories in Dockerized Ubuntu


In this lab exercise, students will learn how to:
Pull an Ubuntu image and run a container.
Find existing Docker containers.
Create a user in Ubuntu.
Create a directory.
Grant a user permissions to a directory.

Exercise 1: Pull an Ubuntu Image and Run a Container

Open a command prompt or terminal window.
Run the following command to pull the latest Ubuntu image:

docker pull ubuntu
Run the following command to start a new container with an interactive bash shell:
docker run -it ubuntu /bin/bash
You should now be in the bash shell of the Ubuntu container.

Exercise 2: List All Docker Containers

Open a new command prompt or terminal window (don't close the existing one where the Ubuntu container is running).
Run the following command to list all running containers:
docker ps
To list all containers (running and exited), use:

docker ps -a

Exercise 3: Create a New User

Return to the terminal window where your Ubuntu container is running.
To add a new user, use the adduser command followed by the desired username (e.g., peter). Make sure the username is in lowercase letters.
bashCopy code
adduser peter
Follow the prompts to set a password and other optional information for the new user.

Exercise 4: Create a Directory

Now, create a new directory using the mkdir command:
bashCopy code
mkdir /home/peter/newdir
This will create a new directory named newdir in the home/peter directory.

Exercise 5: Grant User Permissions to a Directory

Change the ownership of the directory to the new user using the chown command:
bashCopy code
chown peter:peter /home/peter/newdir
To verify that the ownership has been changed, use the ls -l command to list the details of the /home/peter directory:
bashCopy code
ls -l /home/peter
You should see peter listed as the owner and group for newdir.

Exercise 6: Exit the Container and Stop It

To exit the bash shell in the container, type exit and press Enter.
To find the Container ID of the Ubuntu container, use the following command in the new terminal window:
bashCopy code
docker ps -a
To stop the container, type the following, replacing your_container_id with your actual container ID:
bashCopy code
docker stop your_container_id


Be sure to use lowercase letters for usernames as Ubuntu distinguishes between uppercase and lowercase letters.
If you are experiencing issues, make sure to check the container ID with docker ps -a and ensure you are running commands in the correct container.
This concludes the lab exercise. Review your work, make sure you've followed each step accurately, and ask your instructor if you have any questions or need further assistance.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
) instead.