Sign inSign up

csalmeida/clang

By csalmeida

•Updated almost 3 years ago

Installs GCC, Valgrind and wget Useful to generate containers to run C lang programs.

Image
0

10K+

csalmeida/clang repository overview

⁠Clang

This image installs gcc, valgrind and wget and it was intended to be used to run programs written in C.

⁠Docker Compose

The most streamlined way of running a container that loads a project in is probably using docker compose up --detach with the following docker-compose.yml configuration:

services:
  clang:
    image: csalmeida/clang:latest
    working_dir: /home/project/
    stdin_open: true # docker run -i
    tty: true # docker run -t
    volumes:
      - ${PWD}:/home/project

The docker-compose.yml file will pull the image, load an interactive container and add a volume that will keep the project files synced between the host and the container.

Running docker compose up --detach should output should be similar to:

[+] Running 3/3
 ✔ clang 2 layers [⣿⣿]      0B/0B      Pulled                                                                         2.2s
   ✔ f906b88252ef Already exists                                                                                      0.0s
   ✔ 038e21d9091a Already exists                                                                                      0.0s
[+] Building 0.0s (0/0)                                                                                     docker:default
[+] Running 2/2
 ✔ Network c-labs_default    Created                                                                                  0.0s
 ✔ Container c-labs-clang-1  Started  

The container can be accessed:

docker exec -it c-labs-clang-1 /bin/bash

The terminal for the container should be available. Given that there are C files in the folder these can be compiled and run:

root@0e8901c0156c:/home/project/source# gcc -o main main.c
root@0e8901c0156c:/home/project/source# ./main
Hello World!

As files are changed in the text editor on the host machine updates should sync. The program needs to be recompiled each time a change is made.

Valgrid can also be used to check for potential segfaults:

root@567cbfe975b0:/home/project/source# valgrind ./main

⁠Individual Container

To run an interactive container run:

docker run --rm --name clang -it csalmeida/clang

Make a directory for your project:

# root@97742bcc1db2:/#
mkdir -p /home/projects/project_name &&
cd /home/projects/project_name &&

On another terminal in the host project directory copy the files over to the container:

docker cp ./ clang:/home/projects/project_name

Return to the container terminal and compile/run your program:

root@97742bcc1db2:/home/project/project_name# gcc -o main main.c
root@97742bcc1db2:/home/project/project_name# ./main
Hello World!

Tag summary

Content type

Image

Digest

sha256:8734baac8…

Size

280.5 MB

Last updated

almost 3 years ago

docker pull csalmeida/clang