Skip to content

Instantly share code, notes, and snippets.

@rwcitek
Last active August 25, 2024 20:55
Show Gist options
  • Save rwcitek/de57dd0c716248017eec8de791b69611 to your computer and use it in GitHub Desktop.
Save rwcitek/de57dd0c716248017eec8de791b69611 to your computer and use it in GitHub Desktop.
Learning Linux via LinkedIn Learning and Docker

Learning Linux via LinkedIn Learning and Docker

LinkedIn Learning

Here's a link to a LinkedIn Learning course called "Learning Linux Command Line"

https://www.linkedin.com/learning/learning-linux-command-line-14447912/

You can access the course via the ABQ Library website:

https://abqlibrary.org/az/linkedin-learning-formerly-lyndacom

Dockerfile

Here's a Dockerfile to build an image. Save the commands below into a file called Dockerfile.

# Use the official Ubuntu base image
FROM ubuntu:latest

# Specify the shell to be used for RUN commands
SHELL ["/bin/bash", "-c"]

# Prevent interactive prompts during package installation
ARG DEBIAN_FRONTEND=noninteractive

# Unminimize
RUN yes | unminimize

# Update the package list and install sudo
RUN apt-get update && \
    apt-get install -y \
      git \
      jq \
      less \
      man-db \
      nano \
      sudo \
      tree \
      vim \
      zip \
      unzip \
      ;
  
# Rename existing Ubuntu user
ARG USERNAME=scott
RUN usermod -l ${USERNAME} ubuntu && \
    usermod -d /home/${USERNAME} -m ${USERNAME} && \
    usermod -c ${USERNAME^} ${USERNAME}  && \
    groupmod -n ${USERNAME} ubuntu

# Set a password for the new user (change 'password' to a secure password)
RUN echo "${USERNAME}:password" | chpasswd

# Give warning once
RUN echo -e 'Defaults  lecture=once\n\n' >> /etc/sudoers

# Switch to the new user
USER ${USERNAME}

# Set the working directory to the user's home
WORKDIR /home/${USERNAME}

# Set default umask
RUN echo 'umask 002' >> ./.bashrc

# Create README.md file in user's home
RUN cat <<'EOF' > README.md
## Clone git repo from LinkedIn Learning

    git clone https://github.com/LinkedInLearning/learning-linux-command-line-3005201.git Documents

EOF

# Make some folders
RUN mkdir -p Desktop Downloads

# Start an interactive bash shell by default
CMD ["/bin/bash"]

# Copy Dockerfile into image
COPY Dockerfile /

Build the Docker Image

In the same folder where the file Dockerfile is located, run this command.

docker image build -t ubuntu-sudo-user .

Run the Container Instance

docker container run --rm -d --name learn_linux ubuntu-sudo-user sleep inf
docker container exec -i learn_linux /bin/bash README.md
docker container exec -it learn_linux /bin/bash

Stop and Delete the Container Instance

docker container stop learn_linux ubuntu-sudo-user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment